Repository navigation
fix(anthropic)!: route pdf data URIs to document blocks and share the transform with Snowflake - #39977
fix(anthropic)!: route pdf data URIs to document blocks and share the transform with Snowflake#39977mateo-berri wants to merge 33 commits into
Conversation
…ocks A data:application/pdf or data:text/plain URI arriving as a plain image_url block in user content was emitted as an Anthropic image block, which anthropic, bedrock invoke, and vertex all reject with a media_type error. The shared transform now routes those to document blocks the way tool results already did, and requires_inline_base64_media names the dialects that only accept inline base64 media, Snowflake included. Snowflake Cortex Claude requests now go through translate_system_message and anthropic_messages_pt instead of a private copy of the translation. The shared path accepts already-parsed tool-call arguments and dict tool results, and an unparseable tool-call JSON is a 400 SnowflakeException rather than an empty tool input. Snowflake shape assertions follow the shared transform: block-list user content and merged consecutive user turns.
…itellm_lit_6778_snowflake_shared_anthropic_pt
[Medium impact] The latest charset change appears safe to merge, with no new actionable findings SummaryThis PR sends PDF and text attachments as document blocks, preserves answered native The latest change adds six text encodings and regression cases for their labels. No new actionable issues were found Previously acknowledged items remain deferred.
Reviews (25) · Last reviewed commit: "fix(anthropic): decode text attachments ..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…e inline base64 from the Snowflake config Anthropic's base64 document source only accepts application/pdf, so a text/plain data URI (in a file block or in an image_url block) was built into a document the API rejects with a 400. The shared file-block builder now decodes text/plain into a `text` source, which every Anthropic-shaped provider accepts. The shared translator also no longer keeps a provider list for base64-only dialects. Snowflake passes force_base64 into anthropic_messages_pt from its own transformation, and requires_inline_base64_media keeps covering bedrock invoke and vertex the way the inline check did before.
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Parameterized text URIs skip text source
- Normalized the media_type in anthropic_process_openai_file_message by stripping MIME parameters before the text/plain equality check so charset-qualified text/plain data URIs now route to the text source instead of the base64 document Anthropic rejects.
Or push these changes by commenting:
@cursor push a23f4b5e90
Preview (a23f4b5e90)
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py
--- a/litellm/litellm_core_utils/prompt_templates/factory.py
+++ b/litellm/litellm_core_utils/prompt_templates/factory.py
@@ -1904,7 +1904,8 @@
openai_image_url=file_data,
format=format,
)
- if image_chunk["media_type"] == "text/plain":
+ media_type: Final = image_chunk["media_type"].split(";", 1)[0].strip()
+ if media_type == "text/plain":
return AnthropicMessagesDocumentParam(
type="document",
source=AnthropicContentParamSourceText(
@@ -1917,7 +1918,7 @@
type="document",
source=AnthropicContentParamSource(
type="base64",
- media_type=image_chunk["media_type"],
+ media_type=media_type,
data=image_chunk["data"],
),
)
diff --git a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
--- a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
+++ b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py
@@ -3559,6 +3559,9 @@
_TEXT_DATA_URI = "data:text/plain;base64," + base64.b64encode("the secret code word is MANGO\n".encode()).decode()
+_TEXT_DATA_URI_WITH_CHARSET = (
+ "data:text/plain;charset=utf-8;base64," + base64.b64encode("the secret code word is MANGO\n".encode()).decode()
+)
_TEXT_DOCUMENT_BLOCK = {
"type": "document",
"source": {"type": "text", "media_type": "text/plain", "data": "the secret code word is MANGO\n"},
@@ -3570,8 +3573,10 @@
[
{"type": "image_url", "image_url": {"url": _TEXT_DATA_URI}},
{"type": "file", "file": {"file_data": _TEXT_DATA_URI}},
+ {"type": "image_url", "image_url": {"url": _TEXT_DATA_URI_WITH_CHARSET}},
+ {"type": "file", "file": {"file_data": _TEXT_DATA_URI_WITH_CHARSET}},
],
- ids=["image_url", "file"],
+ ids=["image_url", "file", "image_url_with_charset", "file_with_charset"],
)
def test_anthropic_messages_pt_text_plain_data_uri_becomes_text_source_document(block):
"""You can send follow-ups to the cloud agent here.
…rry a charset parameter A data:text/plain;charset=utf-8;base64,... attachment passed the document detection but reached the file-block builder with the parameter still in its media type, so the text/plain comparison missed and the text went out as a base64 document that Anthropic rejects with a 400. The builder now compares the bare media type and decodes the bytes with the charset the URI names, defaulting to utf-8.
|
bugbot run |
The shared transform only passed through server_tool_use and *_tool_result blocks, so replaying a stored conversation whose assistant turn carries a native tool_use block dropped the block and the tool_result that followed had no tool call to point at. Pass it through, deduped against tool_calls that repeat the same id
| return AnthropicContentParamSourceText( | ||
| type="text", | ||
| media_type="text/plain", | ||
| data=base64.b64decode(image_chunk["data"]).decode(content_type_header.get_content_charset("utf-8")), |
There was a problem hiding this comment.
Low: Unbounded text document decoding
An authenticated caller can submit a very large text/plain data URI and force the worker to retain the original base64 string, decoded bytes, and decoded Unicode text simultaneously, exhausting worker memory. Reject documents whose encoded or decoded size exceeds a configured media limit before constructing the text source.
There was a problem hiding this comment.
Same shape as the existing base64 decodes at factory.py:3254 and token_counter.py:232; the max_request_size_mb middleware is the bound on all of them
There was a problem hiding this comment.
Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.
There was a problem hiding this comment.
Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.
PR overviewThe PR routes PDF data URIs to Anthropic document blocks and shares the document transformation with Snowflake. It also updates text attachment decoding and tool-input conversion. One issue has been addressed, but three remain open. Newly accepted tool-input formats let authenticated callers send protected text to Anthropic without the configured pre-call filtering. Text attachment handling also permits memory exhaustion through oversized data URIs and disproportionate CPU consumption through caller-selected decoding, leaving policy-enforcement and worker-availability concerns unresolved. Open issues (3)
Fixed/addressed: 1 · PR risk: 6/10 |
|
bugbot run |
A native `tool_use` block kept its raw id while the matching tool result was sanitized, so replaying a conversation with an id like `functions.Bash:0` still came back as a 400. Both sides go through the same sanitizer now, dedupe compares the sanitized ids, and the block is rebuilt from its own fields so stray keys and a string `input` do not reach the provider. An explicit `format` on an `image_url` or `file` block now decides both whether the attachment is a document and what media type it carries, so a PDF sent under a generic data URI mime reaches Claude as a document. Snowflake turns an attachment whose data URI names an unknown charset into a 400 naming that encoding instead of letting the lookup failure surface as a 500.
|
bugbot run |
… count routes The anthropic, azure_ai and Bedrock Mantle count handlers re-raise a BadRequestError raised before the provider call, and their token counters mark it rejected_before_provider_call, so a framing deployment answers the 400 instead of an estimate that leaves the attachment out, and Mantle no longer turns it into a 500
…flake_shared_anthropic_pt # Conflicts: # litellm/litellm_core_utils/prompt_templates/factory.py
…s format A downloaded text file reaches the decoder without its server's charset since main strips it, so the old hint to name the charset in the data URI could not help a URL caller. A file block's format takes text/plain;charset=... for both URLs and data URIs
|
bugbot run |
| """ | ||
| import json | ||
|
|
||
| if isinstance(arguments, Mapping): |
There was a problem hiding this comment.
Low: New tool-input shapes bypass pre-call DLP
With a pre-call litellm_content_filter blocking/masking rule, an authenticated caller can now submit tool_calls[].function.arguments as {"value":"<protected text>"} and send that value to Anthropic unchanged: ContentFilterGuardrail._get_tool_call_arguments() skips non-strings, while this branch makes the provider conversion accept them instead of rejecting the request. The newly forwarded native tool_use.input blocks at factory.py:3459 also escape OpenAIChatCompletionsHandler._extract_inputs(), which only collects top-level tool_calls; normalize both representations before pre-call scanning, or extend extraction, argument scanning, and rewrite mappings to cover them.
There was a problem hiding this comment.
Snowflake already forwarded both shapes unscanned at the base, so the gap is in the shared guardrail extraction, and it is tracked separately
…of an empty string Snowflake sent json.dumps of a non-string tool result before it moved onto the shared transform, which then sent an empty string for a number or boolean, so Claude lost the answer. Mapping results were already serialized; numbers and booleans now take the same path, and None stays empty as it was on Anthropic
| content_type_header["content-type"] = media_type_with_parameters | ||
| charset: Final = content_type_header.get_content_charset("utf-8") | ||
| try: | ||
| text: Final = base64.b64decode(data).decode(charset) |
There was a problem hiding this comment.
Medium: Caller-selected charset enables quadratic decoding
An authenticated caller can send a file block with file_data set to data:text/plain;charset=punycode;base64, plus base64-encoded b'a' * 524288; Punycode repeatedly copies its growing output, and this approximately 699 KB payload took about 4 seconds in a source-isolated reproduction of the current attachment helper versus under 1 ms on the base revision. (raw.githubusercontent.com) On Bedrock-invoke and Snowflake, this conversion runs on the event loop, letting repeated requests stall unrelated traffic even with a 1 MiB request-size cap.
Restrict charset to an explicit allowlist of bounded-cost text encodings, such as UTF-8 and Latin-1, before calling .decode().
…l or missing content
# Conflicts: # litellm/litellm_core_utils/prompt_templates/factory.py
…n Claude routes A BadRequestError raised by the shared message translation already names its problem, so it no longer carries every message as Received Messages. A 700 KB text attachment with an unsupported charset otherwise answered a 700 KB 400, and redacting that text held the event loop for about 40 s through the proxy.
…n Snowflake Claude Snowflake Claude now builds its system prompt with the shared Anthropic transform, which keeps a message-level cache_control mark on a string system prompt the way the anthropic, vertex, and bedrock routes do. The base dropped that mark on Snowflake alone while it already sent the same block shape for marked system content lists.
|
bugbot run |
…stead of sending the placeholder The empty-text sanitizer only counted tool_calls, thinking, server_tool_use and tool result blocks as content that survives the assistant converter, so a blank text part next to a replayed native tool_use became the protocol placeholder and reached Claude as assistant text. A native tool_use now counts when the next turn answers it, the same check the converter uses before keeping it, so the blank part is dropped there and an unanswered tool_use still gets the placeholder, since the converter drops it and the turn would otherwise be empty
…flake_shared_anthropic_pt # Conflicts: # litellm/litellm_core_utils/prompt_templates/factory.py
…0, as main does Main's #49237 answers 400 naming the first non-string role whatever error the conversion raised. This PR's handler for deliberate translation 400s ran first and skipped that check, so an int or bool role answered "Invalid Message passed in" at the merged tip. The handler now names the role first and keeps its own message otherwise. Main's test for a dropped tool answer id used object tool call arguments as its later failure, which this PR accepts on purpose, so that case now uses list arguments, which still fail.
|
bugbot run |
…on knows The allowlist kept Python codec names for one label per WHATWG encoding, so labels that Python maps to a codec of its own (iso-8859-9, iso-8859-11, tis-620, gb2312, big5-hkscs, ms932) answered 400 instead of decoding. All six are linear table codecs, so the punycode and utf-7 rejection stands
|
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 21d08c8. Configure here.

Handwritten 1-3 sentence description
Original
TLDR
Problem this solves:
image_urlblocks 400 on Claudetool_useblocks are dropped, so tool results 400How it solves it:
documentblocks, and PDF bytes always dotool_useblocks pass through,modify_paramsincludeddrop_paramssends{}for non-object tool inputIntentional product change: without
drop_params, Snowflake now 400s on input it cannot translateFull TLDR
Problem this solves:
image_urlblock is sent as an image and rejectedimage_urlblock is downloaded for bedrock invoke and vertex and sent as an image, so it is rejected tooinput_imageon /v1/responses fails the same way, and so does/utils/token_counterfileblock or animage_urlblock, is sent as a base64 document and rejectedapplication/octet-stream, carries aname=parameter, or whoseformatnames an image type is still sent as an image or rejecteddrop_paramstool_useblock loses it, and the tool result that follows is rejectedtool_useid holds characters Anthropic does not allow, because only the tool result side of the pair is cleaned upmodify_paramson, a replayed nativetool_useanswered by atoolmessage loses that result, and the request is rejectedHow it solves it:
documentblocks for PDF and text data URIs, with text/plain sent as atextsource since Anthropic's base64 source only takes PDFs, decoded with the charset its data URI names when that is a standard text encoding%PDF-signature, so a PDF goes out as a PDF document whatever its data URI orformatsays, and media type parameters likename=are stripped from document blocksformatfield on animage_urlorfileblock otherwise decides whether the attachment is a document and what media type it is sent underimage_urllink goes out as adocumentblock on every dialect that downloads links, whatever itsformatsays, and on anthropic anhttps://link whoseformatsaysapplication/pdfgoes out as a URLdocumentblockrequires_inline_base64_mediahelper names the base64-only dialects, and the Snowflake config asks the shared transform for inline base64 itselfdrop_paramsthrough to it, keeping only the text parts of a system prompt as before. Acache_controlmark on a string system message now reaches Cortex the way it reaches every other Claude route, where the base dropped it on Snowflake alone while sending the same marked block for system content lists. The alternative was dropping it on Snowflake only.test_responses_bridge_message_cache_control_wire.pynow expects the mark on its Snowflake string system rowinput_audio, is a 400 on Snowflake naming the part, or dropped underdrop_params. The base passed it to Cortex untranslatednullor missing tool result goes out as an empty string on every route. At the base, the SDK sent an empty string on the Claude routes andnullon Snowflake, and through the proxy, which drops the null key, the Claude routes answered 400. The alternative wasnullon every routecharset=punycodeattachment held the event loop for seconds, or a WHATWG label table, a new dependency for labels likex-cp1252tool_callsarguments that are not valid JSON, and nativetool_useinput that is not a JSON object, are a 400 naming the tool, or{}underdrop_params. The alternatives were a 400 even underdrop_params, or dropping the whole tool call, which would orphan its tool resulttool_useblocks in an assistant content list go through the shared transform, deduped againsttool_callsthat repeat the same id, with ids run through the same sanitizer as their tool resultsmodify_paramspairstoolmessages with nativetool_useids as well astool_callsidstool_useblock that no later tool result answers is dropped, as at the base, since Anthropic rejects atool_usewith no result. The alternatives were the 400 atool_callsentry gets in that spot, or amodify_paramsstyle repair that invents a result/utils/token_countersends a PDFimage_urlas a document block like the chat request, a downloaded link includedimage_urlorfileblock whoseformatis not a string is handled as ifformatwere absent, so the attachment is typed from its URL and bytes. The alternative was a 400 namingformat, which the base never senttoken_count_framingestimate does not replace, the same way a chat count translation error already answersfileblock'sformat, which takestext/plain;charset=.... The alternatives were re-encoding at fetch, which corrupted binaries a server labels as text, and keeping;charset=in the data URI, which Gemini would forward as its mime typeUser Flow
Before: a developer sends a PDF data URI in an
image_urlblock to Claude and gets a 400image_urlmedia_typeerrortool_useturns get HTTP 400 tooAfter: the same requests are answered from the attachment
Full user flow
Before: a developer sends a PDF as a data URI in an
image_urlblock to a Claude model and gets a 400 backimage_urlblock whose url isdata:application/pdf;base64,...media_type: Input should be 'image/jpeg', 'image/png', 'image/gif' or 'image/webp'fileblock, or as animage_urlblock inside a tool result, is answered normally, so only the plain user-content route is broken. Adata:text/plain;base64,...attachment is HTTP 400 on both routes as well, with the same image error on theimage_urlroute anddocument.source.base64.media_type: Input should be 'application/pdf'on thefilerouteargumentsare not valid JSON is forwarded to Cortex with an empty tool input, with or without"drop_params": truetool_useblock and the next message is that tool's result, is HTTP 400 withunexpected `tool_use_id` found in `tool_result` blockson anthropic, bedrock invoke, and vertex aliketool_useid likefunctions.Bash:0gets the same 400, this time namingfunctions_Bash_0, because the tool result id is cleaned up and the id on thetool_useblock is notdata:application/octet-stream;base64,...in animage_urlblock, with or without"format": "application/pdf", is HTTP 400 with the same imagemedia_typeerror, and bedrock invoke answers the same waycharset=not-a-charsetis forwarded to Cortex as isdata:text/plain;charset=iso-8859-1;base64,...in animage_urlblock, with"format": "text/plain"naming what it is, is HTTP 400 with the same imagemedia_typeerror every text attachment getstool_useblock'sinputis a JSON string rather than an object gets the same 400, because the block is dropped either wayinputis the string"[1, 2]", the replay is the same 400, with or without"drop_params": truedata:application/pdf;name=invoice.pdf;base64,..., is HTTP 400 as animage_urlblock with the imagemedia_typeerror, and as afileblock withmedia_type: Input should be 'application/pdf'media_typeerrorargumentsare not valid JSON is HTTP 400 naming the tool even with"drop_params": truehttps://URL in animage_urlblock is HTTP 400 with the same imagemedia_typeerror, and on anthropic the same link with"format": "application/pdf"is HTTP 400 withThe file format is invalid or unsupportedmodify_params: truein the proxy config, the step 5 replay is HTTP 400 withThis model does not support assistant message prefillinput_audiopart is forwarded to Cortex with theinput_audiopart untranslated, with or without"drop_params": true/utils/token_counter?call_endpoint=truewith the step 15 anthropic link, with or without itsformat, is HTTP 400 with the same imagemedia_typeerrorformatisApplication/PDFis HTTP 400 withThe file format is invalid or unsupported, and adata:TEXT/PLAIN;base64,...attachment, as animage_urlorfileblock, or an octet-stream one whoseformatisText/Plain, is HTTP 400 with amedia_typeerrorformatsaysimage/pngis HTTP 400 withCould not process imageAfter: the same request is answered from the PDF's contents
fileblock and tool-result routes answer the same way as before, POST https://litellm-domain/v1/responses with the PDF as aninput_imageitem is answered too, and the text/plain attachment is answered from its contents on both routes"drop_params": trueit is forwarded with an empty tool input as beforetool_useid likefunctions.Bash:0is HTTP 200 as well, since both sides of the pair get the same cleanupcharset=not-a-charsetcomes back as HTTP 400 naming the encoding litellm could not find, and an attachment with a real charset is forwarded as beforetool_useinput is a JSON string is HTTP 200 as well, since the string is parsed into the object the API expects"[1, 2]"replay is HTTP 400 saying the tool's input must be a JSON object and namingdrop_params, and with"drop_params": trueit is HTTP 200 with an empty input in its place"drop_params": truethat tool call is HTTP 200 and the assistant answers from the tool resultformatsaysapplication/pdf. Without aformat, an anthropic link still goes out as an imagemodify_paramsreplay is HTTP 200 and the assistant answers from the tool resultinput_audiomessage is HTTP 400 naminginput_audio, and with"drop_params": trueit is forwarded without that partformatRelevant issues
Follow-up to #39453
Linear ticket
Resolves LIT-6778
Pre-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: 21d08c8. QA ran on dfcfa0b, and R22 to R26 on the commits their steps name, against merge base 02ef44c. Changes since QA: the commits the /live-pr-risk summaries list and three main merges. Proof remains valid because no earlier case sends those inputs and R16e keeps its 400. Verification: unit tests and make check pass at 21d08c8
tool_usecache_controltool_usereplaystool_useinputdrop_paramsShared setup
Both legs ran the same way on one box: a fresh worktree at the commit named in the heading,
make bootstrap, the same.env, thenpython litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2, one proxy per leg with no database. The change is a per-request translation with no state held in a worker, so one instance per leg covers it. R19b runs on a second proxy per leg, booted the same way fromconfig-modify.yaml, which isconfig.yamlpluslitellm_settings: modify_params: true. anthropic usesANTHROPIC_API_KEY, bedrock invoke uses AWS credentials in us-east-1, and vertex uses service-account credentials.secret.pdf.b64is a one-page PDF whose only text is "The secret code word is PINEAPPLE." and the text attachments read "The secret code word is MANGO." Every call goes through the proxy to the real provider. The one exception is thesnowflake-stubdeployment, whoseapi_baseis a closed local port and whose key is a placeholder, so nothing reaches Cortex and the S cases only show litellm's own handling before the network callThe config, every curl script, both test files, and the raw output of both legs are in this gist. Each script takes the proxy port and reads the proxy key from
QA_KEYBefore (2e5cc9e)
anthropic legs 1-4
zsh qa.sh 21893 anthropic-sonnetOutput
bedrock invoke legs 1-4
Steps and output
bedrock/invoke/us.anthropic.claude-sonnet-5-5, /chat/completions legs 1-3 and /v1/responses leg 4zsh qa.sh 21893 bedrock-invoke-sonnetvertex Sonnet 5.5 legs 1-4
Steps and output
vertex_ai/claude-sonnet-5-5, legs 1-3 and leg 4zsh qa.sh 21893 vertex-sonnetvertex Sonnet 4.6 legs 1-4
Steps and output
vertex_ai/claude-sonnet-4-6, legs 1-3 and leg 4zsh qa.sh 21893 vertex-sonnet-46Streaming leg 1
Steps and output
Leg 1 with
"stream": trueon anthropic and vertexzsh stream.sh 21893risk.sh to snow3.sh
The dependent-path scripts and their output at 2e5cc9e are in this gist
After (dfcfa0b)
anthropic legs 1-4
zsh qa.sh 23417 anthropic-sonnetbedrock invoke legs 1-4
Steps and output
bedrock/invoke/us.anthropic.claude-sonnet-5-5, /chat/completions legs 1-3 and /v1/responses leg 4zsh qa.sh 23417 bedrock-invoke-sonnetvertex Sonnet 5.5 legs 1-4
Steps and output
vertex_ai/claude-sonnet-5-5, legs 1-3 and leg 4zsh qa.sh 23417 vertex-sonnetvertex Sonnet 4.6 legs 1-4
Steps and output
vertex_ai/claude-sonnet-4-6, legs 1-3 and leg 4zsh qa.sh 23417 vertex-sonnet-46Streaming leg 1
Steps and output
Leg 1 with
"stream": trueon anthropic and vertexzsh stream.sh 23417risk.sh to snow3.sh
Eleven dependent-path scripts, steps and output
risk.sh
Steps and output
Dependent paths: tool calls, http image URLs, native /v1/messages, text/plain, cache_control, native tool_use
zsh risk.sh 23417The raw output is after-dfcfa0b043-risk.txt in the gist
risk10.sh
Steps and output
A dirty native tool_use id, and a pdf under a generic data URI mime with and without a format
zsh risk10.sh 23417risk14.sh
Steps and output
A charset-tagged text attachment, and a native tool_use block whose input is a JSON string
zsh risk14.sh 23417risk16.sh
Steps and output
A format Anthropic has no block for, a media type carrying a file name, and an undecodable attachment
zsh risk16.sh 23417risk17.sh
Steps and output
An unanswered native tool_use, pdf bytes under other labels, a named pdf, non-object tool input, drop_params, and token counting
zsh risk17.sh 23417The raw output is after-dfcfa0b043-risk17.txt in the gist
risk18.sh
Steps and output
A native tool_use beside a tool_calls entry, gemini text format, pdf bytes under other labels, and non-object tool_calls arguments
zsh risk18.sh 23417risk19.sh
Steps and output
A pdf linked by https URL on vertex and bedrock invoke, and a native tool_use answered by a tool message on a second proxy whose config sets
modify_params: truezsh risk19.sh 23417 27731risk20.sh
Steps and output
An https pdf link whose
formatsaysapplication/pdfon anthropic, and a user part Cortex Claude cannot take on the Snowflake stub, with and withoutdrop_paramszsh risk20.sh 23417risk21.sh
Steps and output
On anthropic, an
Application/PDFlink anddata:TEXT/PLAINattachments in utf-8 and latin-1 asimage_urlandfileblocks, plus an octet-stream text attachment whoseformatisText/Plain./utils/token_counteron an https pdf link with and without aformat, a bedrock invoke pdf link whoseformatsaysimage/png, and animage_urlwith nourlon the Snowflake stubzsh risk21.sh 23417snow.sh
Steps and output
Snowflake Cortex tool call with broken JSON arguments
zsh snow.sh 23417snow3.sh
Steps and output
Snowflake Cortex text attachment with an unknown charset
zsh snow3.sh 23417R22 number and boolean tool results
Steps and output, before 02ef44c, after 735ace4
A chat completion replays one tool call whose
toolmessage content is the JSON number 7316 or the JSON booleanfalse, with the string"7316"as a control, on each Claude route. Both proxies ran 2 workers from the same configzsh risk22.sh <port>Before, at merge base 02ef44c
After, at 735ace4
R23 null tool results and text charsets
Steps and output, before 02ef44c, after fb753f0
A chat completion replays one tool call whose
toolmessage content isnullon each Claude route and Snowflake. Then a 699 KB text attachment whose data URI sayscharset=punycode, and a Shift JIS one whose data URI names it, go to Claude routes and Snowflake. The Snowflake deployment points at an account that does not exist, so a 404 or 502 means litellm forwarded the request. Both proxies ran 2 workers from the same configzsh risk23.sh <port>Before, at merge base 02ef44c
After, at fb753f0
R24-R26 blank text beside
tool_use, numeric role, charsetsSteps and output, before 02ef44c and 1fecc7a, after 4766510, 4681fbd, and 21d08c8
R24 replays a blank text part beside a native
tool_usethat the nexttoolmessage answers, on four Claude routes, plus one nobody answers, each proxy on 2 workers behind a recorder. At 02ef44c only the placeholder goes out and Claude answers 400. At 1fecc7a the placeholder goes out next to thetool_use, Bugbot's finding. At 4766510 thetool_usegoes out alone. The unanswered one keeps the placeholder on every side. Main's later commits to these files leave both alone. R25 sends a third message with role123at 4681fbd, which answers main's 400 naming the field on all four routes. R26 sends text attachments labeled iso-8859-9, iso-8859-11, tis-620, gb2312, big5-hkscs, and ms932 on three of those routes, which answer 400 on both before trees and MANGO at 21d08c8, Bugbot's second findingzsh risk24.sh <port>zsh risk25.sh <port>zsh risk26.sh <port>Scripts, client output, and the recorded assistant turns are in this gist
Observations from the run
Type
🐛 Bug Fix
🧹 Refactoring
Caveats (if any)
High
Medium
drop_params, Snowflake answers broken tool-call JSON and user parts it cannot translate with a 400Low
tool_useloses itscallerfieldhttps://PDF link with noformatas an image, LIT-9762functionmessages, and Snowflake lifting later system messages, as at the basefileblock'sformatnames the charset, sinceimage_urlignores ittool_useinput, which Snowflake already forwarded and Claude routes now forward tooFinal Attestation
/live-pr-risk at c0b2432
Verdict. Safe to ship, with one decision below on downloaded text that is not utf-8. Every earlier count, PDF, text and tool_result case re-ran base vs c0b2432 on real Anthropic, Azure AI Foundry Claude, Bedrock invoke and Mantle, Vertex Claude, Gemini and Vertex Gemini, plus new count, data URI and downloaded text cases. Each proxy ran 2 workers with a recorder in front of the provider, and c0b2432 merged into main matched every status
Breaking. Bedrock Mantle answered 500 at 3f3f9bd for a text attachment with an unknown charset. f18056a fixes it, and it is a local 400 again
Backward incompatible
fileblock that names the charset informatanswers 200, and d0bb701 points the 400 at itapplication/pdfget a different provider 400formatis ignored, which turns a 400 into 200, as the TLDR says (3f3f9bd)file_idformats, thedrop_params400 for a non-objecttool_use.input, a nameless nativetool_use, placeholder text beside a nativetool_use, dict tool results as JSON text, and Snowflake on the shared transformRegression risk. Downloaded text on the count routes is counted as an image, so chat and count disagree, as at the base. The runtime-to-Mantle count fallback can flag a 400 as rejected before the provider call although bedrock-runtime was called, and nothing reads the flag there. Mantle chat, the Bedrock batch record, claude_platform and opencode_go have no deployment in the rig and are traced only
Not verified. Live Snowflake Cortex, since no credential exists. The SDK
acount_tokensandcount_prompt_tokenserror paths, SSRF blocks and the image size cap on the count routes are traced only/live-pr-risk at fb753f0
Verdict. Safe to ship, with one decision below on Snowflake system prompt cache marks. This run covers the commits since c0b2432. The rig ran merge base 02ef44c, 0e1546b, and fb753f0 side by side on real Anthropic, Azure AI Foundry Claude, Bedrock invoke, and Vertex Claude, plus a Snowflake host that does not exist, each proxy on 2 workers with a recorder in front of the provider. Every outbound request at fb753f0 matched 0e1546b, the branch with main merged in, and only error text and model wording changed
Breaking. Two showed up during the run, and both are fixed here. At 735ace4 a Snowflake
toolmessage with no content answered a 400 naming'content', where the base sent an empty tool result, and 0d18854 sends an empty string again. After Veria's finding, a 699 KB text attachment whose data URI sayscharset=punycodedecoded for seconds on the event loop. 7d5bce3 decodes only standard text encodings, and fb753f0 keeps the request out of that 400, so it answers in 0.12 s where 0e1546b took 42.8 sBackward incompatible
nullor missing tool result goes out as an empty string on every route, where the base answered 400 through the proxy on the Claude routes (0d18854)cache_controlmark on a string system message now reaches Snowflake Cortex, where the base dropped it on Snowflake alone. The base already sent the same marked block to Cortex for system content lists, and Snowflake's prompt caching docs list system messages. Kept on purpose, so Snowflake matches every other Claude route, andtest_responses_bridge_message_cache_control_wire.pynow expects it (1fecc7a)Received Messages=, and no test or caller reads that text (fb753f0)fileblock'sformat, and thatformatanswers 200Regression risk. Main's #49192 conflicted with this PR in the shared tool call conversion, and the merge keeps one
convert_to_anthropic_tool_invokecall that passesdrop_params. Unit tests and the rig pass on it. Pre-call guardrails still skip object tool arguments, a pre-existing gap that is filed. Other translation errors still carry the request in their 400 text, as at the baseDependency graph. The new commits touch the shared tool result text, the text attachment decoder, and the Claude chat error path. Their callers are the anthropic, azure_ai, Bedrock invoke and Mantle, Vertex Claude, and Snowflake chat routes, /v1/messages, /v1/responses through the chat bridge, and the token counters. The rig drove each of them live except Mantle chat and Snowflake, and the count routes sent the same requests as 0e1546b. The old tests/llm_translation and tests/local_testing suites no longer exist, so tests/integration stood in for them. Its providers, security, sdk, extensions, and accounting groups passed at 0e1546b except the Snowflake string system cache row, which passes at 1fecc7a
Not verified. Live Snowflake Cortex, since no credential exists, so how Cortex answers a system prompt cache mark is unproven. Mantle chat, the Bedrock batch record, claude_platform, and opencode_go have no deployment in the rig and are traced only
/live-pr-risk at 4681fbd and 21d08c8
Verdict. Safe to ship. This run covers 488f3d2, the fix for Bugbot's placeholder finding, the third main merge 4766510, 4681fbd, which fixes a clash that merge caused, and 21d08c8, the fix for Bugbot's charset finding. R24 ran 02ef44c, 1fecc7a, and 4766510 side by side on real Anthropic, Bedrock invoke, Vertex Claude, and Azure AI Foundry Claude, each proxy on 2 workers behind a recorder. R25 and R23 ran at 4681fbd on the same routes, and R26 ran 02ef44c, 1fecc7a, and 21d08c8 on three of them
Breaking. Two showed up, and both are fixed here. At 1fecc7a a blank text part beside an answered native
tool_usewent out as the placeholder next to it, and 488f3d2 sends thetool_usealone. At 4766510 a numeric role answered "Invalid Message passed in" instead of main's #49237 400 naming the field, because this PR's handler for deliberate translation 400s ran first. 4681fbd names the role first, and R25 shows it on all four routesBackward incompatible. Nothing new. The fb753f0 entries hold. A #49237 test that used object tool call arguments as a failing input now uses list arguments, since this PR accepts object arguments on purpose
Regression risk. An unanswered native
tool_usestill gets the placeholder, as R24's control shows. The role check returns nothing when every role is a string, so the R23 charset 400 keeps its message. The six codecs 21d08c8 adds are linear table codecs, and the unit tests show punycode and utf-7 still answer 400. Main's #49371 and #47692 changed the same files without touching empty text, roles, ortool_usereplayDependency graph. The sanitizer's only callers are
anthropic_messages_ptand themodify_paramstool pairing, and the role check sits in the Anthropic chat transform. Their callers are the anthropic, azure_ai, Bedrock invoke and Mantle, Vertex Claude, and Snowflake chat routes, /v1/messages and /v1/responses through the chat bridge, and the token counters. The rig drove the four Claude chat routes, and the earlier cases passed again at 4766510. R24 did not run again at 4681fbd, since its roles are stringsNot verified. Live Snowflake Cortex, Mantle chat, /v1/responses, and the token counters for these cases, traced only, and R26 on Bedrock, whose rig credentials had expired
Bugbot summary