Repository navigation
fix(guardrails)!: keep the upstream error when a /v1/messages stream ends in one - #49088
mateo-berri merged 20 commits into
Conversation
…nds in one Raw-SSE guardrail stream hooks assembled the whole stream, and the Anthropic chunk parser raises on an error event, so a stream the upstream ended with event: error failed assembly. tool_permission then blocked it with a 400 that hid the upstream error, bedrock and model_armor emitted a could-not-assemble block, and presidio skipped masking. Assembly now leaves the error events out, so the delivered content is checked as usual and a clean stream passes through with its error frame. A rewritten stream ends with the upstream error instead of a message_delta and message_stop the upstream never sent. tool_permission also passes a stream of only error frames, which carries no tool call to check.
…hen re-emitting a rewritten stream
Merging this PR will not alter performance1 warning
Comparing |
[Medium impact] The changes affect Anthropic streaming when tool permissions or Presidio masking are enabled. The code changes have no new blocking finding, but the required latest-commit live failure proof remains incomplete Findings
SummaryThis PR keeps upstream errors on failed No new actionable issue was found in the changes since the previous review. The Unicode finding is fixed
Reviews (12) · Last reviewed commit: "fix(guardrails): read an error frame as ..." · Reviewed by Greptile |
| try: | ||
| assembled: Final = build_complete_streaming_response( | ||
| all_chunks=(sse_stream,), | ||
| all_chunks=content_events, |
There was a problem hiding this comment.
Required live proof is missing
The repository requires the affected failure to succeed through a real provider at the latest product commit, c91c8e9c6f. The supplied after-fix failures use scripted upstreams. The latest real-provider runs fail before the first byte and do not reach this changed path. Add real-provider proof of the mid-stream error case before merging
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)
There was a problem hiding this comment.
Cases 10a to 10d and 11 relay real Claude Sonnet 5.5 streams from api.anthropic.com, which the relay cuts mid tool input with an injected overloaded_error
There was a problem hiding this comment.
You’re right that cases 10a–10d and 11 use real Anthropic-generated streams: the relay obtains Claude Sonnet 5.5 output from api.anthropic.com and then injects an overloaded_error mid-stream. That is live provider-backed E2E evidence for this bug; the injected failure is appropriate because a real overload is not reliably reproducible. My earlier statement that the relevant after-fix failures were only scripted was incorrect. The remaining question is whether those relay results were run at the latest product commit, c91c8e9c6f; the PR description says the cited relay cases were run on earlier commits, while later QA updates cover cases 14–15.
There was a problem hiding this comment.
QA for 10a, 10b and 11 ran at 1765df5. The later product change only touches streams with no error event, which no relay case sends
There was a problem hiding this comment.
Thanks—cases 10a, 10b, and 11 are live Anthropic-backed relay runs at 1765df54da, and they cover the no-denial path that drops a cut-off tool call. My earlier comment understated that evidence.
One distinction: the latest product commit, c91c8e9c6f, does not only affect streams without an error event. Its changes to Anthropic SSE re-emission apply when a stream ends in an upstream error and a guardrail rewrites it. The allow-all relay cases do not exercise that rewrite path. Case 10c does, but its QA is listed at an earlier commit; case 14 is listed at 8d0606f555 and uses a scripted upstream. So the existing relay proof covers the passthrough behavior, but not the rewritten error-stream behavior at c91c8e9c6f. A live-provider relay run for that rewrite case at the latest product commit would close the remaining gap.
There was a problem hiding this comment.
You're right. I misidentified c91c8e9c6f as the latest product commit; it predates 3db8b99312. The later product change, 8d0606f555, is in the no-denial/cut-off-call path, and the denial-rewrite behavior covered by live case 10c was already present and tested at 3db8b99312. I retract my claim that the later change affected that rewrite path.
The only remaining distinction is commit alignment: the review rule requires live proof at the latest product commit (8d0606f555) or later. So the concern, if retained, is that case 10c's live run is from an earlier commit—not that the denial-rewrite path was untested.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…y an upstream error tool_permission and Presidio now assemble an error-ended stream through the error with an opt-in keyword, leaving out a tool call or thinking block the upstream cut off. Logging, OpenTelemetry, Bedrock, and Model Armor keep the old assembly. A rewrite drops the text block stop only when the upstream left its text block open.
…ch rewritten block before the next starts A failed stream holding a cut-off tool_use is now re-emitted through the rewrite, which leaves the call out and keeps the upstream error, so a denied call never reaches the client. The rewrite leaves its text block open only when it is the last block, and keeps a message_delta the upstream sent before failing. The new tool_permission tests no longer patch should_run_guardrail.
… sent, minus the cut-off tool call Re-emitting such a stream through the rewrite sent an empty text block and stopped it, and Claude Code does not retry a failed stream that shows a finished block, so it showed a mid-response error instead of retrying. Dropping only the cut-off call's events keeps the stream as the upstream sent it.
…tream failed Assembly leaves unfinished blocks out of the check only when the stream carries an upstream error event, so a stream with an unfinished but allowed tool call and no error frame now reaches the client as sent instead of losing a call the check already read
1 similar comment
…eading a stream A data line holding a bare JSON value such as 5 made the stream helpers call .get on an int, so tool_permission and Presidio answered 500 where main answered 400 or passed the stream through
…es the same way everywhere Run the skip for a data line that is not a JSON object through extract_sse_data and the assembler loop, so the usage fallback keeps a stream's tokens and the chat handler keeps its contract. Presidio now holds a leading non-object frame until the first object frame, so the rest of the stream is still masked or blocked. An event: error frame now counts by its name, so a rewrite keeps it.
…y kind of tool call A non-object JSON line with no Anthropic frame after it now gets a 400 from Presidio before any data byte, since passing it would send text main refused. A frame named error stays a normal event when its data is another Anthropic event. server_tool_use and mcp_tool_use cut off by an upstream error are dropped like tool_use, and a leading frame with empty data is relayed at once.
…ine and keep non-string error types out of the frozenset Presidio now refuses a stream assembly cannot read when it holds a non-object data line, instead of relaying it unmasked. Non-string event types no longer crash a rewrite, and a CRLF stream that opens with a typed error is no longer read as one error, so its tool calls are still checked.
… Presidio Presidio passed PII at 200 where main answered 500 when the first read was a JSON object with a list or dict type, or a JSON array with a character cut at the end of the read. has_unreadable_json_event now reads both as data no reader of these streams can take, so the first-frame check refuses them.
…omes before a Gemini stream The first read then holds the unreadable line behind one Presidio can pass, so the check has to look at every frame in it.
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
…ame is an error A tool call split over data: lines beside one error frame read as error-only, so tool_permission passed it, and an SDK joins those lines and reads the call. The check now joins a frame's data lines and refuses anything but an error.
… could read a frame differently Run 8 of the live risk pass showed each stream reader imitating a client and missing a shape: a whitespace-led data line, an error key with no type, a split tool call after a plain message_start. An error frame now has to be plain, and assembly past an error returns None for any frame a client could read differently, so those streams keep main's refusal.
…ion read A failed stream now reaches the client through the rewrite that already serves a denial, followed by the upstream error, even when nothing is denied. Raw frames could carry a tool call the check never read in shapes such as a reused block index, mixed line ends, a tool in message_start, interleaved deltas, or a form feed, and each refusal rule only moved the search to the next shape. The error frame goes out as its event name and first data line. An error is found at CR, LF and CRLF line ends, and the rewrite adds no finished block when it read no text, so Claude Code still retries the stream.
…e error alone when a rewrite cannot be built A data-less event: error frame with junk after the name is an unknown event to both SDKs, so a healthy stream stays raw. A finished tool call whose input is not JSON cannot be rebuilt, so a failed stream sends its upstream error alone, and a healthy stream still raises as before.
…ep its JSON whole Only the last event line of a frame a blank line ended names an error, so a healthy stream with a later event line or an unterminated error is no failed stream. Any rebuild failure on a failed stream now sends the upstream error alone with a warning, a param rule denies an input nested too deep, and a raw line break inside a JSON error stays escaped so every reader gets it whole.
|
bugbot run |
|
|
||
| def _has_non_object_data(event_str: str) -> bool: | ||
| data_start: Final = event_str.find("data:") | ||
| return data_start != -1 and not event_str[data_start + len("data:") :].lstrip().startswith("{") |
There was a problem hiding this comment.
Event skip uses substring data match
Medium Severity
_has_non_object_data and the fast-path skip locate data: with a raw substring search instead of the line-based field parse used by _sse_data_payload. A comment or earlier field that contains data: makes the whole frame look non-object, so assembly drops it. On a healthy stream tool_permission then sees no tool, returns the raw chunks, and a denied call in that frame can reach the client unchecked.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 99425d5. Configure here.
There was a problem hiding this comment.
This matches main, where the converter's same substring search hides that frame on a healthy stream. A failed stream now drops the hidden call
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
1 issue from previous review remains unresolved.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 99425d5. Configure here.
…ream error Upstream BerriAI#49088 made anthropic_sse_chunks_from_response re-emit a stream that the upstream ended in an error event with that error again, never with a message_delta or message_stop the upstream did not send. ThirdLaw rewrites the native Messages body through anthropic_sse_chunks_from_body instead, which still closed the message normally, so a rewrite hid the upstream error and Claude Code did not retry. anthropic_sse_chunks_from_body now takes the source chunks and shares the ending logic with the response path. ThirdLaw passes the buffered stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6wUmDJhvBeMaAGXcd2qWv
An Anthropic-format upstream that sends a data line holding a JSON number, string, array or null (data: 5) failed /v1/chat/completions and /v1/responses with "'int' object has no attribute 'get'", and the agentic /v1/messages iterator sent an error event after message_stop. The shared stream parser now skips such a line the way SSE clients ignore an event they do not understand This line has no BerriAI#49088, so the /v1/messages pass-through log assembler also gets that PR's skip of a data line that does not start with "{" in its text fast path, and the chat handler test gets the _streamed_text helper main already has (cherry picked from commit ebe3712)


When an Anthropic /v1/messages stream failed partway through, tool_permission replaced the upstream's error with its own 400, even when every tool is allowed, so Claude Code stopped instead of retrying. Presidio skipped masking these streams too
On such a stream it now checks what arrived before the error and sends only that, then the error, so a denied tool is still blocked and a cut-off tool call is dropped. A failed upstream no longer logs as a guardrail failure, and an error-only stream writes no spend row, as with no guardrail
Original
Breaking change: a /v1/messages stream that fails upstream behind tool_permission now gets the upstream error, not a 400. That is a 200 stream carrying the error event, or the upstream's own status when the error comes in the chat or Gemini form. Behind Presidio an analyzer failure on such a stream now errors it. Clients that matched that 400 should read the upstream error
TLDR
Problem this solves:
How it solves it:
User Flow
Before: behind a tool_permission guardrail, Claude Code gets a guardrail error when Anthropic overloads mid-answer
ANTHROPIC_BASE_URLand type a prompt"stream": true, and Anthropic fails mid-answer withoverloaded_errorAPI Error: 400 ... (not a parseable Anthropic SSE stream)After: Claude Code sees the overload and recovers, as with no guardrail
overloaded_errorframeDecisions
through_upstream_error, that tool_permission and Presidio turn on. Alternativestool_use,server_tool_useormcp_tool_use) or a cut-off thinking block is left out, because its input is only the start of a JSON object that cannot be parsed or matched against a param rule, and cut-off thinking has no signature. Alternativesevent: errorframe holds another Anthropic event, since that frame counts as content, so a call hidden past such a frame reaches the client as it does on main. This changes the wire format of a failed stream, which the client could have taken as it arrived, and the guarantee cannot hold on raw frames, so that is the reason for the bridge. The rewrite keeps text, finished tool calls and thinking, and the upstream message id and model. It merges text blocks into one before the tool calls, drops citations, pings, web search results and a finishedmcp_tool_use, turnsserver_tool_useintotool_use, emptiesredacted_thinking, keeps onlyinput_tokensin themessage_startusage, drops a tool'scallerand the nullcontainer,stop_detailsanddiagnosticskeys, sends each block as one delta, and keeps acompactionblock unread. Main answered 400 on these streams, except one whose error frame is empty,null, a list, an unknown object or several lines, which it sent at 200. A client retries them or shows the error. A response the rewrite cannot build, such as a finished tool call whose input is not a JSON object, is too long, is nested too deep or was masked into invalid JSON, leaves the client the upstream error alone, not the text before it, and the proxy logs a warning. That stream has nomessage_start, so both SDKs raise on its first event, and no tool call or denial text reaches the client. Presidio sends that input to its analyzer first, so when the analyzer fails on it (a 200 KB nested input did, after 30 to 66 seconds of pings) the client gets an in-bandinvalid_request_errorit does not retry, where main sent the stream raw. A healthy stream still raises there as on main, except that a param rule now denies an input nested too deep instead of answering 500. The rewrite adds no finished block when it read no text, because Claude Code does not retry a stream that shows one. Alternativesmessage_start, interleaved deltas and a form feed, and each fix only moved the search to the next shapemessage_deltaandmessage_stopthe re-emit used to add, keeping each one only when the upstream sent it. It also leaves the text block open when the upstream never stopped its text block, unless the round trip puts a tool call after that text. Then the text block stops first, since a client must see each block stop before the next one starts. Sending the other frames would tell the client the message or a block finished normally after an upstream failure, which fix(anthropic): surface Responses bridge stream failures as Anthropic error events #43126 already ruled out for the Responses bridge. The error goes out asevent: errorand its firstdata:line, since anything else in that frame is content no guardrail read. A raw U+2028, U+2029 or U+0085 inside a JSON object goes out escaped, so the object stays whole for every reader. Anything else, a JSON string or array included, is cut at the first of them, and both SDKs raise on the cut textevent:line names it, since both SDKs dispatch that way. A frame whose laterevent:line replaced the error reads as no error, so its stream passes as on main. An error frame cut before its blank line reads as no error too. After content the stream gets what main gives it, and a plain one alone passes raw behind tool_permission, where main answered 400, so both SDKs read no event, as with no guardrail. By its datatype, or by an exactevent: errorline unless the data is another Anthropic event, because a client SDK raises on that line alone and reads any other name as a different event. Anevent: errorframe holding a content delta stays content, so Presidio masks it and a rewrite sends it once. Atypethat is not a string is read as no type, so theevent:line decides, and Presidio refuses a first read whosetypeis a list or a dicttypeis a list or a dict. When assembly can read the rest of the stream, it skips the line and masks the stream. When no Anthropic frame is in the first read, or assembly cannot read the stream, it refuses, since it cannot check the text. Main crashed on most of these with a 500, and it sent some at 200 with text unmasked when a line it passes came first or invalid UTF-8 hid the line. The refusal is a 400 when no byte went out yet and an in-band error after a preface. A ping can make the first read look Anthropic, so frames assembly can read then answer a masked 200, not the refusal. A client that retried main's 500 does not retry this refusal. With a message id, a refusal writes a failure row, a success row, and two Langfuse traces. With no message id it writes one row under the call id. On some streams a race decides whether that row is the failure or a success at 0 tokens, and a merge with current main usually leaves the success, so a refused request can read as a success. On Presidio's Gemini route it applies where main answered 500, and where a word or null line came first and main sent the text unmasked at 200. A stream with no such line keeps passing, and so does one whose first read holds only a JSON object of no known kind, with any othertypeor nonedata:line is relayed at once, like a comment keepalivedata:line, exact field names,event: erroror noevent:line, and onlytype,errorandrequest_idat the top of the JSON. Lines are cut at every break a client honors,str.splitlinesbeing the widest. Comments, a bareevent:line anddata: [DONE]do not count. Anything else counts as content, so a tool call hidden behind a form feed or an emptydata:line cannot pass this way, and neither can an error message with a raw U+2028, which gets main's refusal.event: errorthen a U+001C anddata:on one line passes raw at the widest cut, where main refused, and a client reads an empty stream, as it does with no guardrail. Text inside an error's own message passes, as it does with no guardrail. Anevent: errorframe with anothertypecounts as an error on a stream with content, but not here, so Model Armor refuses it where main sent it at 200. The cost is that an upstream adding a new top-level key to its error frames gets a refusal in place of its error, until the list changes. That beats a list of content keys, since each provider has its own (message,candidates,choices). A CR or CRLF stream that opens with a typed error is now read frame by frame, so Model Armor blocks it in-band where main passed its frames, and tool_permission checks it. Model Armor also blocks in-band an error stream with anid:orretry:frame, a BOM, or the error inside anevent: pingframe, which main passed. A finished tool call before the block is still checked, and a denied one still gets the denialPre-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: 99425d5. QA ran the guarded side of every case on 1e11e9c except case 9 and case 17, which ran on 99425d5. Case 9 and the no-guardrail sides ran on 3db8b99, or 1765df5 for 10a and 11, or 8d0606f for 14. Later changes only touch how a guardrail handles a stream with an error frame, and those runs send none through a guardrail. 1e11e9c to 99425d5 changes which frames count as an error and what a failed stream sends when a rewrite cannot be built. Every other guarded case sends a blank-line-ended error frame and parseable tool input, so each reads the same. Verification: unit tests, case 17, and /live-pr-risk ran those shapes and the no-guardrail cells at 99425d5
config.yaml
Cases 7, 9, 11 to 15 and 17 drive Claude Code in tmux, and the rest use curl. Anthropic entries leave out
api_keyhere.scriptedmodels stream a local fake overload, andrelaymodels cut a real Claude Sonnet 5.5 stream with an injectedoverloaded_errorls, allow-alllsruleCase 13. Claude Code, guarded, real Sonnet 5.5 cut mid-answer
litellm --config config.yaml --port $PORT --num_workers 2ANTHROPIC_BASE_URL=http://127.0.0.1:$PORT ANTHROPIC_AUTH_TOKEN=$LITELLM_MASTER_KEY ANTHROPIC_MODEL=litellm-qa-toolperm-relay-text-guarded claudeWrite two short sentences about the ocean.and press EnterBefore (d9c9d84), all 3 cut streams got the 400:
After (1e11e9c), the retry after the first cut got the answer:
Case 13, the same model with no guardrail
Model
litellm-qa-toolperm-relay-text. Both trees fall back to one non-streaming request and answerBefore (d9c9d84):
After (3db8b99):
Case 7, Claude Code on a guarded model whose scripted upstream always overloads
Model
litellm-qa-toolperm-scripted-text-error-guarded, same steps as case 13. Prompt:Say helloBefore (d9c9d84), at 3 seconds:
After (1e11e9c), 7 seconds in, and once its retries run out:
No guardrail, Before (d9c9d84) and After (3db8b99):
Case 12, Claude Code on real Claude Sonnet 5.5 whose first stream is cut mid-answer
Models
litellm-qa-toolperm-relay-text-onceandlitellm-qa-toolperm-relay-text-once-guarded, same steps and prompt as case 13. The relay cuts only the first stream of a session. Claude Code answered on both trees, guarded or not, since on d9c9d84 it sends a new request after the guardrail 400Before (d9c9d84), guarded:
After (1e11e9c), guarded:
Case 11, Claude Code on real Claude Sonnet 5.5 whose first Bash call is cut mid-input
Models
litellm-qa-toolperm-relay-tool-onceandlitellm-qa-toolperm-relay-tool-once-guarded, same steps as case 13. Prompt:Use the Bash tool to run: ls -la /usr/share && echo done-listing-the-share-directory, then tell me how many entries it printed.The relay cuts only the first stream of a sessionBefore (d9c9d84), guarded:
After (1e11e9c), guarded:
After (1765df5), no guardrail:
Case 9, Claude Code on real Claude Sonnet 5.5, guarded, runs Bash ls
Model
litellm-qa-toolperm-sonnet-guarded, same steps as case 13. Prompt:Use the Bash tool to run ls in this directory, then tell me how many entries there are.Both trees ran the tool through the guardrail and answeredBefore (d9c9d84):
After (3db8b99):
Case 14, Claude Code on a scripted upstream that streams a finished Read call, then overloads, rewrite mode
Models
litellm-qa-toolperm-scripted-read-errorandlitellm-qa-toolperm-scripted-read-error-rewrite-guarded(denyRead, rewrite), same steps as case 13. Prompt:Show me the contents of /etc/hostsBefore (d9c9d84), guarded:
After (1e11e9c), guarded. The denial replaces the Read call, and the upstream error follows, so Read never runs:
After (8d0606f), no guardrail, the same error after the Read call, which Claude Code then offers to run:
Case 15, Claude Code on a scripted upstream that streams a phone number, then overloads, Presidio output masking
Models
litellm-qa-presidio-scripted-phone-errorandlitellm-qa-presidio-scripted-phone-error-guarded, same steps as case 13. Prompt:How do I reach you?Claude Code drops text cut off by an overload without showing it, then retries non-streaming untilAPI Error: 500 ... overloaded_error, on both trees with or without the guardrail. No capture on either tree shows212-555-0199, so case 6 shows the masking on the wireAfter (1e11e9c), guarded:
Case 17, Claude Code when a finished Bash call cannot be rebuilt, so the client gets the upstream error alone
Models
litellm-qa-toolperm-relay-badinput-onceandlitellm-qa-toolperm-relay-badinput-once-guarded, same steps as case 13. Prompt:Use Bash to run ls in /tmp, then tell me how many entries it printed.The relay answers the first request itself with text, a finished Bash call whose input is{"command" "ls", and an overload, then forwards later requests to the real APIBefore (d9c9d84), guarded, the stream is a 400 and Claude Code retries it with nothing on screen:
After (99425d5), guarded, the curl stream is the error alone. Claude Code shows
API error · Retrying in 1s · attempt 1/2, retries, runs Bash and answers:After (99425d5), no guardrail, Claude Code shows the text, the malformed call and
API Error: Server error mid-response, then goes on in the next turn:Case 10a. Real Sonnet Bash call cut mid-input, allow-all
Before (d9c9d84)
After (1e11e9c)
Case 10b. Real Sonnet Bash call cut mid-input, Bash allowed only for `ls`
Before (d9c9d84)
After (1e11e9c)
Case 10c. Real Sonnet Read then Bash, Bash cut mid-input, deny Read in rewrite mode
Before (d9c9d84)
After (1e11e9c)
Case 10d. Real Sonnet phone number then a cut Bash call, Presidio output masking
Before (d9c9d84)
After (1e11e9c)
Case 1. Text then overload, no guardrail
Before (d9c9d84)
After (3db8b99)
Case 1. Text then overload, allow-all tool_permission
Before (d9c9d84)
After (1e11e9c)
Case 2. Allowed Bash tool call then overload, allow-all
Before (d9c9d84)
After (1e11e9c)
Case 3. Denied Read tool call then overload, block mode
Before (d9c9d84)
After (1e11e9c)
Case 4. Denied Read tool call then overload, rewrite mode
Before (d9c9d84)
After (1e11e9c)
Case 5. Error frame only, allow-all, the same bytes as no guardrail
Before (d9c9d84)
After (1e11e9c)
Case 6. Phone number then overload, Presidio output masking
Before (d9c9d84)
After (1e11e9c)
Case 16. Real Sonnet thinking, then text cut by an overload, adaptive thinking
No guardrail (1e11e9c, each signature cut to 16 characters here)
allow-all (1e11e9c)
/live-pr-risk at 99425d5
Verdict: passes at 99425d5. Base d9c9d84, head 99425d5, merged with main c4b01b2, 679 cells on each with 2 workers, real upstreams and real Presidio. Failures are injected into real streams. Nothing on the merge differs from head alone, and every entry below is disclosed
Breaking
A deep tool input then an upstream error behind Presidio mask (200 KB of nested
[) was 200 with the phone number raw on main. It is now a 200 with pings, then an in-bandinvalid_request_error, because the real analyzer answered 500 after 30 s, and the client waited 32 to 66 s. No text or PII reaches the client and both SDKs raise, but the retryable overload became a class a client does not retry. At 20 KB the error comes alone. Disclosed, ships on mateo-berri's approval of this PRBackward incompatible
A stream whose only frame is a plain error cut before its blank line was 400 behind tool_permission and is now 200 raw, with or without a deny rule. Both SDKs read no event, as with no guardrail, and no call can pass. Behind Presidio it is raw as on main, and any other lone cut frame keeps main's 400. Disclosed, ships on mateo-berri's approval of this PR
An error that is a JSON string or array with a raw U+2028 was 400 and is now 200 with the error cut, and both SDKs raise on the cut text. Disclosed, ships on mateo-berri's approval of this PR
A failed stream behind tool_permission answers a 200 stream with the error, not a 400. Disclosed, ships on mateo-berri's approval of this PR
A rewrite that cannot build sends the error alone, with no denial text and no call. Disclosed, ships on mateo-berri's approval of this PR
Presidio block answers 400 on readable PII before an error. Disclosed, ships on mateo-berri's approval of this PR
A param rule now denies an input nested too deep, where main answered 500. Disclosed, ships on mateo-berri's approval of this PR
The error goes last and keeps only its first
data:line. Disclosed, ships on mateo-berri's approval of this PRRegression risk
The catch-all swallows every Exception on a failed stream, so a real rewrite bug shows only as one fixed warning with no exception text, request id or guardrail name. CancelledError, KeyboardInterrupt, SystemExit and GeneratorExit pass, no guardrail decision sits inside it, and no denied call that main blocked came out in 162 live deny cells
Presidio passes an unterminated typed error frame raw with its PII, the same on main, so this is a leak this PR leaves alone. With a BOM the proxy follows the Python SDK and TS differs. One first-pass failure row went missing on an unterminated frame and did not reproduce in 3 more runs
Dependency graph
_frames_a_client_dispatchesreaches only_error_events, thenanthropic_sse_error_events, then the tool_permission hook andanthropic_sse_chunks_from_responsefrom tool_permission and Presidio, all verified live. Model Armor and Bedrock reach the rewrite in process only.is_sse_error_streamstill counts an unterminated frame, verified live. The route throughcommon_request_processingand the string hook dispatch inproxy/utils.pywas driven by every cell. No subclass or registry entry. Unit tests passed on head and merged. The walk named no dependent the integration suites cover, so they were skippedNo-guardrail cells ran at this tip. Real streams cut mid-text and mid-tool read with both SDKs are no worse than base, and with no guardrail they match base
Not verified
Bedrock's rewrite and Model Armor's sanitized rewrite ran in process only, with no Bedrock guardrail credentials or sanitizing template here. Model Armor with
fail_on_error: falseon a deep frame was not driven. The fidelity sample was not re-run, since this diff does not change what the rewrite keeps. 65 cells with no error frame were carried from earlier tips. Claude Code on the in-band refusal was not drivenType
🐛 Bug Fix
Caveats (if any)
Medium
Low
fail_on_error: falseevent: errorholding another Anthropic event, a shape the check cannot read (saydata:in a comment) passes, as on mainFinal Attestation
Bugbot summary