Skip to content

feat: env var overrides for extraction and query prompts#2944

Open
NaveRazy-Rhino wants to merge 1 commit intoHKUDS:mainfrom
NaveRazy-Rhino:feat/env-prompt-overrides
Open

feat: env var overrides for extraction and query prompts#2944
NaveRazy-Rhino wants to merge 1 commit intoHKUDS:mainfrom
NaveRazy-Rhino:feat/env-prompt-overrides

Conversation

@NaveRazy-Rhino
Copy link
Copy Markdown

Description

Add environment variable overrides for the key prompts in lightrag/prompt.py, allowing users to customize entity extraction, summarization, and query prompts without modifying source code.

This is a minimal, non-breaking bridge until the full prompt template management system (#2652) lands. It follows the same pattern LightRAG already uses for ENTITY_TYPES and SUMMARY_LANGUAGE.

Related Issues

Changes Made

lightrag/prompt.py (42 lines added):

  • Added import os, json
  • Added env var override loop at module bottom: if an env var is set, it replaces the corresponding PROMPTS entry; otherwise the hardcoded default is preserved
  • 6 string prompt overrides: ENTITY_EXTRACTION_SYSTEM_PROMPT, ENTITY_EXTRACTION_USER_PROMPT, SUMMARIZE_ENTITY_DESCRIPTIONS_PROMPT, RAG_RESPONSE_PROMPT, NAIVE_RAG_RESPONSE_PROMPT, KEYWORDS_EXTRACTION_PROMPT
  • 2 list prompt overrides (JSON arrays): ENTITY_EXTRACTION_EXAMPLES, KEYWORDS_EXTRACTION_EXAMPLES

env.example (15 lines added):

  • Documented all new env vars with usage notes, placed next to ENTITY_TYPES

Why This Matters

Domain-specific use cases — code analysis, legal, medical, DevOps — need different extraction prompts. For example, the default prompt title-cases all entity names (Split And Save Layers), which is wrong for code identifiers that must preserve snake_case. Currently the only options are editing prompt.py directly or monkey-patching at runtime.

This PR lets users set ENTITY_EXTRACTION_SYSTEM_PROMPT in .env and get custom extraction behavior with zero code changes, zero new dependencies, and zero risk to existing users.

Example Usage

# In .env — customize for code analysis
ENTITY_TYPES='["Function", "Class", "Module", "ConfigKey", "Service", "Concept"]'
ENTITY_EXTRACTION_SYSTEM_PROMPT='---Role---\nYou are a Code Knowledge Graph Specialist...\n(custom prompt preserving snake_case identifiers)'

Checklist

  • Changes tested locally
  • Pre-commit checks pass (pre-commit run --all-files)
  • Documentation updated (env.example)
  • Zero breaking changes — all overrides are optional with existing defaults
  • No new dependencies

Additional Notes

This is intentionally minimal. The full prompt template system in #2652 (Jinja2, git-backed, WebUI editor) is the right long-term solution. This PR is a 57-line bridge that unblocks the community today — it can be deprecated when #2652 merges.

…mpts

Allow users to customize entity extraction, summarization, and query
prompts via environment variables without modifying source code.

This is a common request (HKUDS#308, HKUDS#1672, HKUDS#2623) — domain-specific use
cases (code analysis, legal, medical) need different extraction prompts
but currently require editing prompt.py directly.

Each override is optional. If the env var is not set, the hardcoded
default is used. String prompts are set directly; list prompts (examples)
are parsed as JSON arrays.

This is a lightweight, non-breaking bridge until the full prompt template
management system (HKUDS#2652) is available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Entity Types and Prompts

2 participants