Send a file a tool returns as a note when the model can't read it, with `supports_audio_file_input` and `supported_document_media_types` profile flags

Merged
DO
1mo ago
+1029-1183
  • Part of #10472 (steps 1 and 2). FileUnderstanding (#8453) builds on these flags and lands after this; widening the harness read_file (step 4) is a later PR.

Why

A tool returning a file the model can't take ends the run today: the adapter's message mapping raises before anything is sent (audio and video on Anthropic and OpenAI Responses, video on Chat Completions, everything but images on Groq and Hugging Face, ...), and Cohere drops the file silently (#7646). The model asked the tool for that file; the user didn't choose to send it, so the run should go on and the model should be told what it couldn't see.

What changes

Profile flags. ModelProfile says which kinds of file the model takes: supports_image_input, supports_document_input and supports_video_input, plus:

  • supports_audio_file_input: supports_audio_input already exists and means "retained realtime speech is replayed as audio", which no shipping profile sets; reusing it would have changed what realtime handoff sends. The _file_ names what this one is about: an AudioUrl or audio BinaryContent.
  • supported_document_media_types: frozenset[str]: Anthropic reads PDFs and plain text but raises on Word, Excel, CSV, HTML and Markdown; Mistral reads PDFs and inlines text but raises on Word and Excel. A boolean would either break their PDFs or keep the run-ending error. The set only narrows the known DocumentMediaTypes; a document of any other media type is judged by supports_document_input alone.

All file-input flags default to True now, and each adapter class declares what its mapping refuses in two private class variables (_unsupported_file_inputs, _supported_document_media_types) that Model.profile applies after every other layer, the way it already intersects supported_native_tools with what the class implements. A default of False would have changed behavior for every model that never declared a value (FunctionModel, TestModel, OpenRouter's video, third-party adapters); this way only what an adapter says it refuses is affected, and OpenRouter can lift Chat Completions' video limit just by declaring nothing.

Adapterimagedocumentdocument media typesaudio filevideo
AnthropicModelyesyesPDF, text/plainnono
OpenAIChatModelyesyesall; text only when openai_chat_supports_document_input=False (Azure, Alibaba, ...)yesno
OpenRouterModelyesyesallyesyes, unless the upstream profile says no (Gemini image models)
OpenAIResponsesModel (+ Codex, Bedrock Mantle)yesyesallnono
GroqModelyesnon/anono
HuggingFaceModelyesnon/anono
MistralModelyesyesPDF and textnono
XaiModelyesyesallnono
BedrockConverseModelyesyesallnoyes, except Amazon models other than Nova Lite/Pro/Premier
CohereModelnonon/anono
MCPSamplingModelyesnon/anono
DecisionModelsper classnon/anono
GoogleModelyesyesallyesyes, except image models

Each limit is declared once, on the adapter, so provider profiles and the model-family profiles they share stay as they are, and the profile matrix shows only what a model family says.

For OpenAIChatModel without document input (Azure, Alibaba, ...), supported_document_media_types narrows to the text types rather than turning documents off, because the mapping still inlines those as text: turning documents off would have replaced a text file a tool returned with a note.

The note. Model.prepare_messages runs per model and per FallbackModel candidate (and in Temporal's re-preparation), so each candidate applies its own profile. It replaces a file inside a ToolReturnPart that the profile says this model can't read with:

File d9a13f (audio/mpeg, 48,213 bytes) was not sent: this model cannot read audio files.

The size appears for BinaryContent only (a URL's size isn't known without downloading it), and the media type is left out when a URL's can't be inferred. Replacing the file on the ToolReturnPart covers both the files sent inside the tool result and those core moves to the user channel with <tool_result> framing, since that move happens later in the adapter. Stored history is untouched.

Not replaced: files in a user prompt (the user chose them, so they still raise), ToolReturn.content (documented as user content the developer chose to add), and UploadedFiles (only their provider can read them).

Verification

  • tests/test_unreadable_tool_files.py: the note and its wording per kind, history untouched, user prompt and ToolReturn.content untouched, a user-prompt file still raising on Anthropic, per-candidate FallbackModel behavior, each adapter's resolved flags, and adapter narrowing over a user profile.
  • test_multimodal_tool_return_matrix: the combinations that used to raise (or reach the API and 400) for a directly returned file now assert the note in the follow-up request. That follow-up is answered by a test wrapper rather than recorded, since recording needs a live call per combination; two OpenAI Responses cassettes lose the follow-up interaction they no longer make. ToolReturn.content and UploadedFile combinations keep their errors.
  • Decision-model and Hugging Face tests that asserted a tool's file raises now assert the note.
For maintainers
  • Every file-input flag defaults to True, so a model that declares nothing keeps today's behavior; only what an adapter says it refuses becomes a note.
  • Bedrock non-Nova video is still sent (the Converse mapping sends it, and the API rejects it for Claude); declaring it off would mean a provider-level per-family flag and snapshot churn across the profile matrix. Same for OpenRouter, where the upstream decides.
  • MCPSamplingModel raises on any file in a tool result, images included; only documents, audio and video become notes, since images in user prompts work there.
  • The class variables are private. They could be public like supported_tool_deferral_modes if third-party adapters should declare them too.
  • A text-like document a model can't take (CSV on Anthropic) gets a note, though it could have been inlined as text; doing that from prepare_messages is easy for bytes but would need a download for a DocumentUrl, and prepare_messages is synchronous.

Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code