Repository navigation
fix(guardrails): mask reasoning text on /v1/responses output - #52504
mateo-berri merged 9 commits into
Conversation
Post-call masking guardrails only saw the answer on /v1/responses, so a reasoning summary, the Claude bridge's reasoning content, and the thinking text inside its encrypted_content and provider_specific_fields reached the client raw. Scan those texts with the answer, answers first, and write the mask back to the response and every stream event. Thinking signatures stay untouched so the blob still replays.
A guardrail that reads one end of its text list overwrote the answer with masked reasoning when both shared one call. Each distinct reasoning text now gets its own apply_guardrail call after the answer rewrite, and whole-response scanners keep one call.
# Conflicts: # litellm/llms/openai/responses/guardrail_translation/handler.py # tests/unit/llms/openai/responses/test_openai_responses_guardrail_handler.py
PR overviewThe PR updates guardrail handling for /v1/responses output to mask reasoning text, including buffered streams and synthetic response envelopes. One issue has been addressed, but two open gaps still allow released stream content to escape guardrail checks. A partial terminal envelope can leave buffered reasoning unchecked, while a synthetic envelope for a cut-short stream can omit refusal text from final moderation and audit checks. These gaps can allow blocked content to pass through under those stream conditions. Open issues (2)
Fixed/addressed: 1 · PR risk: 6/10 Reviews |
| self._sync_stream_events_with_output_rewrites(responses_so_far, response_obj, reasoning_rewrites) | ||
|
|
||
| envelope_has_scannable_content: Final = bool(texts_to_check or tool_calls_to_check or reasoning_texts) | ||
| if envelope_has_scannable_content and not answer_outside_envelope: |
There was a problem hiding this comment.
Medium: Buffered reasoning can bypass scanning with a partial envelope
A nonempty reasoning_texts does not prove the envelope covers the buffered stream: with reasoning deltas at output indices 0 (clean) and 1 (SECRET), followed by response.incomplete containing only index 0, a guardrail that blocks SECRET now scans only clean and returns the unchecked index-1 delta; the base implementation blocked this sequence through the string fallback. Compare buffered reasoning positions against the terminal envelope and scan or reconstruct missing parts before returning.
There was a problem hiding this comment.
Fixed in cafc01f. Streamed reasoning that a cut-short final event lacks now gets its own guardrail call, and the mask reaches the stream
There was a problem hiding this comment.
Still fixed at 53c350d. test_reasoning_a_partial_envelope_lacks_is_scanned_and_masked streams reasoning an incomplete envelope lacks and asserts it is scanned and masked
There was a problem hiding this comment.
Ran your exact sequence at 1739875 with a guardrail that blocks SECRET. It scans clean and SECRET, then raises, so the stream is blocked
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…nd send reasoning in one call A stream cut short by max_output_tokens can end with a terminal envelope that lacks reasoning it already streamed, so that reasoning skipped BLOCK and MASK. It now gets its own guardrail call and the mask reaches its stream events. Every distinct reasoning text now goes to the guardrail in one call instead of one call per text. A guardrail that returns a different number of texts falls back to one call per text so each text keeps its own rewrite.
[High impact] The changes since the previous review appear safe to merge.
|
| incomplete: Final = ResponsesAPIStreamEvents.RESPONSE_INCOMPLETE.value | ||
| envelope: Final = {"type": incomplete, "response": response} | ||
| return (*responses_so_far, envelope) | ||
| return (*responses_so_far, _released_envelope(responses_so_far)) |
There was a problem hiding this comment.
Medium: Synthetic envelopes skip released text
A cut-short buffer with clean reasoning and output-text deltas plus a response.refusal.delta containing a blocked value now receives a synthetic envelope that omits the refusal; _scan_released_stream_after_disconnect() and _scan_pipeline_stream_cut_short() then scan only the clean envelope, so that value never reaches the final moderation/audit check. Check _has_unplaceable_stream_text() here as well and retain a fallback scan for emitted text the envelope cannot represent.
There was a problem hiding this comment.
Fixed in 2be3f95. A cut-short stream with a refusal or code interpreter text now skips the synthetic envelope and goes to the full fallback scan
There was a problem hiding this comment.
Still fixed at 53c350d. test_a_refusal_released_next_to_reasoning_reaches_the_guardrail_after_the_stream_is_cut_short cuts a stream after a blocked refusal delta and asserts the guardrail scans it
There was a problem hiding this comment.
Ran your sequence at 1739875 with a guardrail that blocks SECRET. No synthetic envelope is added, the fallback scans the refusal, and it blocks
…rail batches, keep the judge on the answer A guardrail that reads one end of its text list now checks every reasoning text, the content filter keeps one call for all of them, llm_as_a_judge judges the answer alone, and a legacy hook keeps its answer mask when reasoning streams past a cut-short final event
| case "response.content_part.added" if content_position in rewrites.contents and stream_item_field( | ||
| part, part_field | ||
| ): | ||
| write_field(part, part_field, rewrites.contents[content_position]) |
There was a problem hiding this comment.
Latest streaming fix lacks QA. Live QA must cover the latest product commit. Rerun
36750f3dd9 with nonempty response.content_part.added reasoning.
Rule Used: Apply this rule only to PRs that fix LLM translation bugs or add LLM translation features. LLM translation means converting requests, responses, streaming events, tool calls, and errors between the API a caller uses on LiteLLM (any endpoint or SDK fu... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Neither Claude nor gpt-5.6 streams a non-empty reasoning content_part.added, and litellm opens parts empty, so no live leg reaches it. A unit test covers it
There was a problem hiding this comment.
That’s a fair point. I shouldn’t require a live leg for an event the tested providers don’t emit; the unit test is the appropriate coverage for that branch.
The remaining gap is QA freshness, not that specific event: the PR says live QA ran on 2be3f95882, while 36750f3dd9 is the latest product commit. Please rerun the existing reachable live QA cases on 36750f3dd9 and update the proof. No need to manufacture a non-empty response.content_part.added event.
There was a problem hiding this comment.
Re-ran the reachable live QA at 53c350d, now the latest product commit, and the After proof in the description shows that run
There was a problem hiding this comment.
Re-ran the live QA at 1739875, the latest product commit, and the After proof in the description now shows that run
…t the judge read reasoning Reasoning texts go to a guardrail in one call after the answer by default. Guardrails that read one end of texts (Qualifire, HiddenLayer, Gray Swan, Ovalix, custom code, CollieAI, Bedrock latest-message-only) opt out through scans_each_text_separately and get one call per text. A batch answered with a different number of texts is re-sent one text per call. llm_as_a_judge takes the answer and the reasoning in one call through scans_all_response_texts_in_one_call, and scans_reasoning is removed
|
bugbot run |
…provider thinking in an empty output
1 similar comment
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1739875. Configure here.
A masking guardrail on the Responses API only masks the answer, so the word it should hide still reaches the client through the reasoning
This PR sends the reasoning to the guardrail in one call after the answer and masks the response and every stream event. Claude's signatures stay, so the reasoning still replays on the next turn
Original
TLDR
Problem this solves:
/v1/responsesencrypted_contentandprovider_specific_fieldsHow it solves it:
Intentional product change: BLOCK now also fires on a reasoning-only match, with 400 or
response.failedinstead of 200.User Flow
Before: a developer behind a masking guardrail still sees the masked word in the reasoning of a
/v1/responsesreplypersimmon"reasoning": {"effort": "high", "summary": "detailed"}and"stream": true[KEYWORD_REDACTED]response.reasoning_summary_text.doneandoutput[0].summarystill showpersimmon, and on Claude so doesencrypted_contentAfter: the reasoning carries the same mask as the answer and the next turn still works
persimmon"reasoning": {"effort": "high", "summary": "detailed"}and"stream": true[KEYWORD_REDACTED][KEYWORD_REDACTED], and no event has the raw wordPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Last updated: 1739875. /live-pr-risk ran on 53c350d. Since then, a stream with no final event masks reasoning only its finished item holds, and an empty output masks provider thinking. No dependent changed, and an empty reply without thinking makes no guardrail call. Verification: old and new code agree on 55 captured streams
Each leg ran 2 uvicorn workers per proxy and its own Redis, against real OpenAI, Anthropic, Vertex, Azure AI Foundry, and Databricks. Reasoning cases retry up to 15 times until the word appears
Setup
pipeline.yaml:direct.yamlhas the same first two models, the same guardrail withdefault_on: trueand only thepersimmonrule, the same Redis block, and no policy. The before leg ran its own Redis on another portresponse.failedGET /v1/responses/{id}/v1/chat/completionsand/v1/messagesClaudeBefore (436f6d5)
gpt-5.6 stream
post gpt-stream.sse "$(body gpt-5.6 true)"Every other case, before
gpt-5.6 non-stream
post gpt-nonstream.json "$(body gpt-5.6 false)"jq -c '[.output[] | if .type=="reasoning" then {type, summary: ([.summary[].text]|join(" ")|.[0:140])} else {type, text: .content[0].text} end]' gpt-nonstream.jsonOpenAI Python SDK 2.54.0 stream
Claude non-stream
post claude-nonstream.json "$(body claude-sonnet-5-5 false)"jq -c '{content: ([.output[]|select(.type=="reasoning")|.content[]?.text]|join(" ")|.[0:90]), blob: ([.output[]|select(.type=="reasoning")|.encrypted_content]|join(" ")|.[0:90]), provider: (.provider_specific_fields.thinking_blocks[0].thinking//""|.[0:90]), answer: ([.output[]|select(.type=="message")|.content[0].text]|join(" ")), has_signature: ([.output[]|select(.type=="reasoning")|.encrypted_content]|join(" ")|contains("signature"))}' claude-nonstream.jsonClaude stream
post claude-stream.sse "$(body claude-sonnet-5-5 true)"gpt-5-mini stream cut short by
max_output_tokenspost gpt-truncated.sse "$(jq -nc --arg q "$TRUNC_PROMPT" '{model:"gpt-5-mini",stream:true,input:$q,tools:[{type:"web_search"}],max_output_tokens:1500,reasoning:{effort:"medium",summary:"detailed"}}')"Direct
default_onguardrail, no policy, gpt-5.6 non-streamjq -c '[.output[] | if .type=="reasoning" then {type, summary: ([.summary[].text]|join(" ")|.[0:140])} else {type, text: .content[0].text} end]' direct-gpt-nonstream.jsonPlain answer with no reasoning
post plain-answer.json '{"model":"gpt-5.6","input":"Reply with exactly this word and nothing else: persimmon"}'jq -c '[.output[]|select(.type=="message")|.content[0].text]' plain-answer.jsonClaude tool replay
post claude-tool-1.json "$(jq -nc --arg q "$TOOL_PROMPT" --argjson t "$TOOLS" '{model:"claude-sonnet-5-5",input:$q,tools:$t,tool_choice:"auto",max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"}}')"post claude-tool-2.json "$(jq -c --arg q "$TOOL_PROMPT" --argjson t "$TOOLS" '{model:"claude-sonnet-5-5",tools:$t,max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},input:([{role:"user",content:$q}] + [.output[] | del(.status)] + [{type:"function_call_output",call_id:(.output[] | select(.type=="function_call") | .call_id),output:"found: orange fruit"}])}' claude-tool-1.json)"jq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' claude-tool-1.jsonClaude replay with no tool
post claude-replay-2.json "$(jq -c '{model:"claude-sonnet-5-5",max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},input:([{role:"user",content:"Name the fruit from before."}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' claude-nonstream.json)"Vertex Claude tool replay
claude-sonnet-vertex, saved asvertex-tool-1.jsonandvertex-tool-2.jsonjq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' vertex-tool-1.jsonAzure AI Foundry Claude tool replay
claude-opus-foundry, saved asfoundry-tool-1.jsonandfoundry-tool-2.jsonjq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' foundry-tool-1.jsonDatabricks Claude tool replay
claude-databricks, saved asdatabricks-tool-1.jsonanddatabricks-tool-2.jsonjq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' databricks-tool-1.jsongpt-5.6 replay, stateless
post gpt-state-1.json "$(body gpt-5.6 false | jq -c '. + {store:false,include:["reasoning.encrypted_content"]}')"post gpt-state-2.json "$(jq -c '{model:"gpt-5.6",store:false,include:["reasoning.encrypted_content"],reasoning:{effort:"low"},input:([{role:"user",content:"Name the fruit."}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' gpt-state-1.json)"gpt-5.6 replay, stored
post gpt-stored-2.json "$(jq -c '{model:"gpt-5.6",reasoning:{effort:"low"},input:([{role:"user",content:"Name the fruit."}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' gpt-nonstream.json)"Claude replay with no word to mask
post claude-clean-1.json '{"model":"claude-sonnet-5-5","input":"Think about what 12 times 12 is, then reply with only the number.","max_output_tokens":6000,"reasoning":{"effort":"high","summary":"detailed"}}'post claude-clean-2.json "$(jq -c '{model:"claude-sonnet-5-5",max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},input:([{role:"user",content:"What is 12 times 12?"}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' claude-clean-1.json)"BLOCK word only in the reasoning, non-stream
post block-nonstream.json "$(jq -nc --arg q "$BLOCK_PROMPT" '{model:"gpt-5.6",input:$q,max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"}}')"jq -c '.error.message // ([.output[]|select(.type=="reasoning")|.summary[]?.text]|join(" ")|.[0:140])' block-nonstream.jsonBLOCK word only in the reasoning, stream
post block-stream.sse "$(jq -nc --arg q "$BLOCK_PROMPT" '{model:"gpt-5.6",input:$q,max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},stream:true}')"GET /v1/responses/{id}jq -c '[.output[] | if .type=="reasoning" then {type, summary: ([.summary[].text]|join(" ")|.[0:140])} else {type, text: .content[0].text} end]' retrieve.json/v1/chat/completionsClaude, not changed by this PRjq -c '.choices[0].message | {content, reasoning_content: (.reasoning_content//""|.[0:90])}' chat-claude.json/v1/messagesClaude, not changed by this PRjq -c '[.content[] | {type, text: ((.text // .thinking // "")|.[0:90])}]' messages-claude.jsonAfter (1739875)
gpt-5.6 stream
post gpt-stream.sse "$(body gpt-5.6 true)"Every other case, after
gpt-5.6 non-stream
post gpt-nonstream.json "$(body gpt-5.6 false)"jq -c '[.output[] | if .type=="reasoning" then {type, summary: ([.summary[].text]|join(" ")|.[0:140])} else {type, text: .content[0].text} end]' gpt-nonstream.jsonOpenAI Python SDK 2.54.0 stream
Claude non-stream
post claude-nonstream.json "$(body claude-sonnet-5-5 false)"jq -c '{content: ([.output[]|select(.type=="reasoning")|.content[]?.text]|join(" ")|.[0:90]), blob: ([.output[]|select(.type=="reasoning")|.encrypted_content]|join(" ")|.[0:90]), provider: (.provider_specific_fields.thinking_blocks[0].thinking//""|.[0:90]), answer: ([.output[]|select(.type=="message")|.content[0].text]|join(" ")), has_signature: ([.output[]|select(.type=="reasoning")|.encrypted_content]|join(" ")|contains("signature"))}' claude-nonstream.jsonClaude stream
post claude-stream.sse "$(body claude-sonnet-5-5 true)"gpt-5-mini stream cut short by
max_output_tokenspost gpt-truncated.sse "$(jq -nc --arg q "$TRUNC_PROMPT" '{model:"gpt-5-mini",stream:true,input:$q,tools:[{type:"web_search"}],max_output_tokens:1500,reasoning:{effort:"medium",summary:"detailed"}}')"Direct
default_onguardrail, no policy, gpt-5.6 non-streamjq -c '[.output[] | if .type=="reasoning" then {type, summary: ([.summary[].text]|join(" ")|.[0:140])} else {type, text: .content[0].text} end]' direct-gpt-nonstream.jsonPlain answer with no reasoning
post plain-answer.json '{"model":"gpt-5.6","input":"Reply with exactly this word and nothing else: persimmon"}'jq -c '[.output[]|select(.type=="message")|.content[0].text]' plain-answer.jsonClaude tool replay
post claude-tool-1.json "$(jq -nc --arg q "$TOOL_PROMPT" --argjson t "$TOOLS" '{model:"claude-sonnet-5-5",input:$q,tools:$t,tool_choice:"auto",max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"}}')"post claude-tool-2.json "$(jq -c --arg q "$TOOL_PROMPT" --argjson t "$TOOLS" '{model:"claude-sonnet-5-5",tools:$t,max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},input:([{role:"user",content:$q}] + [.output[] | del(.status)] + [{type:"function_call_output",call_id:(.output[] | select(.type=="function_call") | .call_id),output:"found: orange fruit"}])}' claude-tool-1.json)"jq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' claude-tool-1.jsonClaude replay with no tool
At this tip one of four runs of this replay got HTTP 200 with Anthropic's terms-of-service refusal as the message. The other three completed. Each replayed thinking that carried the mask
post claude-replay-2.json "$(jq -c '{model:"claude-sonnet-5-5",max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},input:([{role:"user",content:"Name the fruit from before."}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' claude-nonstream.json)"Vertex Claude tool replay
claude-sonnet-vertex, saved asvertex-tool-1.jsonandvertex-tool-2.jsonjq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' vertex-tool-1.jsonAzure AI Foundry Claude tool replay
claude-opus-foundry, saved asfoundry-tool-1.jsonandfoundry-tool-2.jsonjq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' foundry-tool-1.jsonDatabricks Claude tool replay
claude-databricks, saved asdatabricks-tool-1.jsonanddatabricks-tool-2.jsonjq -c '[.output[]|select(.type=="reasoning")|tostring|ascii_downcase|{word: contains("persimmon"), masked: contains("keyword_redacted")}]' databricks-tool-1.jsongpt-5.6 replay, stateless
post gpt-state-1.json "$(body gpt-5.6 false | jq -c '. + {store:false,include:["reasoning.encrypted_content"]}')"post gpt-state-2.json "$(jq -c '{model:"gpt-5.6",store:false,include:["reasoning.encrypted_content"],reasoning:{effort:"low"},input:([{role:"user",content:"Name the fruit."}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' gpt-state-1.json)"gpt-5.6 replay, stored
post gpt-stored-2.json "$(jq -c '{model:"gpt-5.6",reasoning:{effort:"low"},input:([{role:"user",content:"Name the fruit."}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' gpt-nonstream.json)"Claude replay with no word to mask
post claude-clean-1.json '{"model":"claude-sonnet-5-5","input":"Think about what 12 times 12 is, then reply with only the number.","max_output_tokens":6000,"reasoning":{"effort":"high","summary":"detailed"}}'post claude-clean-2.json "$(jq -c '{model:"claude-sonnet-5-5",max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},input:([{role:"user",content:"What is 12 times 12?"}] + [.output[] | del(.status)] + [{role:"user",content:"Now say done."}])}' claude-clean-1.json)"BLOCK word only in the reasoning, non-stream
post block-nonstream.json "$(jq -nc --arg q "$BLOCK_PROMPT" '{model:"gpt-5.6",input:$q,max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"}}')"jq -c '.error.message // ([.output[]|select(.type=="reasoning")|.summary[]?.text]|join(" ")|.[0:140])' block-nonstream.jsonBLOCK word only in the reasoning, stream
post block-stream.sse "$(jq -nc --arg q "$BLOCK_PROMPT" '{model:"gpt-5.6",input:$q,max_output_tokens:6000,reasoning:{effort:"high",summary:"detailed"},stream:true}')"GET /v1/responses/{id}jq -c '[.output[] | if .type=="reasoning" then {type, summary: ([.summary[].text]|join(" ")|.[0:140])} else {type, text: .content[0].text} end]' retrieve.json/v1/chat/completionsClaude, not changed by this PRjq -c '.choices[0].message | {content, reasoning_content: (.reasoning_content//""|.[0:90])}' chat-claude.json/v1/messagesClaude, not changed by this PRjq -c '[.content[] | {type, text: ((.text // .thinking // "")|.[0:90])}]' messages-claude.jsonsdk_stream.py
Seen during QA, the first three left alone by this PR:
Type
🐛 Bug Fix
Caveats (if any)
High
Medium
response.failedwith HTTP 200textsmask only that end of the reasoningscans_each_text_separately, so a Generic Guardrail API server has nonellm_as_a_judge, and test guardrails ran live. Other vendors were unit tested or traced onlyLow
Final Attestation
Decisions
redacted_thinkingkept, and the bytes stay the same when nothing matched. I rejected dropping the block (it loses the reasoning on the next turn) and leaving it raw (it leaks). A live probe showed Anthropic checkssignatureand not thethinkingtext, with edited text at 200 and a tampered signature at 400 on claude-opus-5-5, claude-sonnet-5-5, claude-sonnet-4-6, claude-sonnet-4-5, and claude-haiku-4-5. Opaque OpenAI blobs are left alone. An unverifiable block inside a verifiable blob is masked toooutput_index, the same key the response positions use, rather thanitem_id.addedevents are written only when their text is non-empty, andresponse.reasoning_text.*events are handled even though the event enum lacks themhiddenlayer,grayswan,ovalix, and customer guardrails can read one end oftexts. Claude reasoningcontentwas in the answer call at the merge base, so a guardrail that reads the first text now reads the answer thereapply_guardrailtakes a list and applies to every text in it. A guardrail that opts out throughscans_each_text_separatelygets one call per text instead, and so does a batch that comes back with a different number of texts, so a guardrail that returns one text never fails the reply or leaves a text raw. Qualifire, HiddenLayer, Gray Swan, and Bedrock withexperimental_use_latest_role_message_onlyread one end, Ovalix raises only for the last text, and custom code and CollieAI run code this repo cannot see, so all of them opt out. I rejected one call per text for every guardrail, which cost 1 + N vendor calls for N texts, and an opt-in on each of the 30 or so built-ins that read every text. I also rejected running the answer and reasoning calls at the same time. It saves one guardrail round trip, but Akto reads the whole response in the reasoning call and blocks when an answer it masked is still raw there. A customer guardrail that reads one end gets one call too and masks only that end of the reasoning until it opts outscans_all_response_texts_in_one_call. Separate calls would run the hook once per text and put reasoning into the answer. It skips the extra pass for reasoning that a cut-short final event left out, so that reasoning stays raw as at the merge basestreaming_iterator.pyis not touched_open_item_stateand_open_item_closing_eventsare not touched, because.addedhas no reasoning text on real streamscontentand does not scan OpenAI summariestexts(Straiker v3, Onyx) scans it once more in the reasoning call. I left those vendors alone. XecGuard readschoices, which a Responses API reply does not have, so it scans nothing on/v1/responsesat the merge base or heremax_output_tokenscan end with a final event that lacks reasoning it already streamed. That reasoning gets its own call and its mask goes to the stream events, while the final event keeps what the provider sent. The merge base caught this case only through the old fallback, which blocked but never maskedllm_as_a_judgetakes the answer and the reasoning in one call throughscans_all_response_texts_in_one_call, so it makes one model call and judges both. At the merge base it judged Claude reasoning, which was in the answer call, and not OpenAI summaries. I rejected skipping reasoning, which stopped judging Claude reasoning, and a second judge call, which doubles its model cost/live-pr-risk at 53c350d
Base 436f6d5. Both sides ran 2 uvicorn workers with Postgres, and recorders in front of OpenAI and Anthropic. The rig's guardrails read one end of
textsor record what they get, like a custom guardrail wouldBreaking: none. A guardrail that reads and sends back only the last text now masks every reasoning text, and
llm_as_a_judgenow judges gpt-5.6 reasoning toollm_as_a_judge, gpt-5.6llm_as_a_judge, ClaudeBackward incompatible: BLOCK on reasoning alone (Decision 17), one more guardrail call for the reasoning (Decision 8), Claude reasoning out of the answer call except for a guardrail that takes every text at once (Decisions 7 and 16), and masked text in non-stream logs. A custom guardrail that reads one end of
textsand sends every text back masks only that end of the reasoning until it opts out (Decision 8).scans_each_text_separatelyandscans_all_response_texts_in_one_callare new and additive, and the policy stream wrapper forwards bothRegression risk: Akto maps masks by exact text over the whole response, which one call with all reasoning keeps working. Straiker v3 and Onyx scan the whole response once more in the reasoning call. Both are traced only
Not verified: Bedrock guardrails and Bedrock Claude replay (no AWS access), Qualifire, HiddenLayer, Ovalix, Gray Swan, CollieAI, Akto, Straiker, and a stream that ends with no final event after a refusal. Each opt-out except CollieAI's, whose package is not installed here, has a unit test that fails without it
Bugbot summary