Conversation
…eplayed history (#255, #256) Two retriever RAG safety findings from audit #226, both in RAGService.ask(). #255: a blocked response set blocked_reason to the specific SafetyViolationType (prompt_injection, moderation_flagged, or hallucination), giving a caller a 3-way oracle to tell which rail a payload tripped and tune bypasses against it. Every block path now returns one undifferentiated BLOCKED_REASON ("blocked"); the specific violation type stays in server-side logs only. #256: only the newest question passed through check_input; prior conversation_history turns were appended verbatim to every later model call with no re-screening, recirculating anything that entered a turn unscreened (for example via the retrieved-chunk path). ask() now re-screens stored history before generation via _screen_history, dropping and logging unsafe turns, mirroring the existing retrieved-chunk screening. Placed after the cache lookup so a cache hit skips the work. Tests: oracle-closure test (two rails, identical reason) and history drop/keep tests added; existing block-reason assertions and the injection integration test updated to the collapsed contract.
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.
Summary
Two retriever RAG safety findings from audit #226, both surgical edits to
RAGService.ask(). Hand-batched into one PR because both touch the sameask()method and cannot run as parallel workstreams.#255 —
blocked_reasondisclosed which safety rail firedA blocked
/askresponse setblocked_reasonto the specificSafetyViolationType(prompt_injection,moderation_flagged, orhallucination), giving a caller a 3-way oracle: an attacker probing for bypasses could tell from the response alone which rail a payload tripped and tune against it.Every block path now returns one undifferentiated
BLOCKED_REASON("blocked"). The specific violation type stays in server-side logs only, so observability is unchanged.#256 — replayed conversation history was never re-screened
Only the newest question passed through
check_input(). Priorconversation_historyturns were copied and appended verbatim to every later model call, recirculating anything that entered a turn unscreened (for example via the retrieved-chunk path).ask()now re-screens stored history via a new_screen_history()helper before generation, dropping and logging unsafe turns. This mirrors the existing retrieved-chunk screening idiom (drop + log, not block). Placed after the cache lookup so a cache hit skips the extra safety calls.Tests
blocked_reason, proving no differentiation.complete_with_history.Gate:
ruff format/ruff checkclean,mypy --strictclean, 385 unit tests pass at 89.5% coverage.Closes #255
Closes #256