fix(gateway): scope answers to the question's subject on both answer prompts - #176
Merged
Merged
Conversation
…prompts Harden both answer system prompts so retrieved passages about a *different* subject (person / product / entity) than the question are not presented as the answer — the model must say the context lacks the answer instead. Applied to _ANSWER_SYSTEM_PROMPT (/v1/query) and INJECTION_RESISTANT_SYSTEM_PROMPT (the injection-resistant answer surface). Also gitignore .env.openai. Verified: ruff, ruff format, mypy --strict (gateway + injection), pytest (injection + gateway + red-team prompt-injection suite). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(gateway): scope answers to the question's subject
Both answer system prompts now instruct the model that retrieved passages about a
different subject (person / product / entity) than the question must not be
presented as the answer — it must say the context doesn't contain the answer
instead. This reduces a class of confident-but-wrong answers when retrieval
surfaces near-miss passages.
Applied symmetrically to both answer surfaces:
_ANSWER_SYSTEM_PROMPT—/v1/queryINJECTION_RESISTANT_SYSTEM_PROMPT— the injection-resistant surface (Step 7.3)Also
.gitignores.env.openaiso the local OpenAI-demo secret can't be staged.Verification (local)
ruff+ruff format✅ ·mypy --strict(gateway + injection) ✅pytestinjection + gateway + the red-team prompt-injection suite ✅ (theprompt still excludes the injection payload and retains the "untrusted" framing,
so the 7.3 invariants hold)
🤖 Generated with Claude Code