Repository navigation
fix(providers): label tool result media sent in a Chat Completions user message - #84
Merged
Merged
Conversation
…er message A Chat Completions tool message holds only text, so tool result media goes in a synthetic user message, which gives tool output the user's authority. That message now starts with a text part that names the tool call and says the content is tool output, not instructions from the user. Part of CODAGT-1430
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
ethanndickson
marked this pull request as ready for review
November 4, 2026 06:32
ethanndickson
added a commit
to coder/coder
that referenced
this pull request
Nov 5, 2026
A Chat Completions tool message holds only text, so fantasy sends tool result media in a user message right after it. That gave tool output the authority of the user's own words. coder/fantasy#84 puts a text part ahead of the media that names the tool call and says the content is tool output, not instructions from the user. The PDF tool result test now expects that label.
ethanndickson
added a commit
to coder/coder
that referenced
this pull request
Nov 9, 2026
A Chat Completions tool message holds only text, so fantasy sends tool result media in a user message right after it. That gave tool output the authority of the user's own words. coder/fantasy#84 puts a text part ahead of the media that names the tool call and says the content is tool output, not instructions from the user. The PDF tool result test now expects that label.
ethanndickson
added a commit
to coder/coder
that referenced
this pull request
Nov 9, 2026
A Chat Completions tool message holds only text, so fantasy sends tool result media in a user message right after it. That gave tool output the authority of the user's own words. coder/fantasy#84 puts a text part ahead of the media that names the tool call and says the content is tool output, not instructions from the user. The PDF tool result test now expects that label.
ethanndickson
added a commit
to coder/coder
that referenced
this pull request
Nov 9, 2026
A Chat Completions tool message holds only text, so fantasy sends tool result media in a user message right after it. That gave tool output the authority of the user's own words. coder/fantasy#84 puts a text part ahead of the media that names the tool call and says the content is tool output, not instructions from the user. The PDF tool result test now expects that label.
ethanndickson
added a commit
to coder/coder
that referenced
this pull request
Nov 10, 2026
Part of CODAGT-1430 Relates to CODAGT-1541 Stacked on #31743. This bumps fantasy to pick up coder/fantasy#84 and coder/fantasy#85. A Chat Completions tool message can only hold text, so fantasy sends tool result media (images, audio, and now PDFs from #31384) in a `role: "user"` message right after it. That gives whatever the tool returned the authority of the user's own words, which Codex flagged on #31383 as a prompt injection risk for MCP tools that return untrusted files. coder/fantasy#84 starts that user message with a text part naming the tool call and saying the content is tool output, not instructions from the user. It only changes the Chat Completions paths (`openai` without the Responses API, `openaicompat`, OpenRouter and Vercel); Anthropic and Responses keep the media inside the tool result. AI Bridge records the last user message's text as the prompt, so on the step after a tool returns media, it'll now record the label. I think that's fine for now. coder/fantasy#85 fixes the output token limit field. The OpenAI provider sent `max_tokens` unless the model ID looked like a reasoning model, and reasoning models reject it: ``` Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead. ``` That breaks any reasoning model whose ID fantasy doesn't recognise, e.g. an Azure deployment name, which doesn't say what model it serves (Azure providers start using this client in #31952). The OpenAI provider now sends `max_completion_tokens` on every Chat Completions request, which is what OpenAI deprecated `max_tokens` in favour of. `openaicompat`, OpenRouter and Vercel keep `max_tokens`, so self-hosted servers behind the OpenAI Compatible provider are unaffected. I've added a test that checks the field on each route, and the models docs no longer say Max Completion Tokens is only for reasoning models.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to CODAGT-1430
A Chat Completions tool message can only hold text, so when a tool returns an image, audio or a PDF, we answer the tool call with a text tool message and put the media in a synthetic
role: "user"message after the run of tool messages. That message holds nothing but the media, so content that a tool controls (say, a PDF that an MCP server fetched) reaches the model with the authority of the user's own words. Codex flagged this on coder/coder#31383, as #74 adds PDFs to this path, but images and audio have gone this way for a while, upstream included.To fix, that message now starts with a text part that names the tool call and says it's tool output:
litellm and pydantic-ai label it the same way. It's only a soft boundary, as models can follow injected text in a tool message too, but it gets back the provenance we lose by switching roles. This covers openai, openaicompat, openrouter and vercel. Anthropic
tool_resultand Responsesfunction_call_outputalready keep media in the tool position, so they're unchanged.One knock-on for coder/coder: AI Bridge records the text of a trailing user message as the prompt, so after the bump, a chatd step that follows tool media on a Chat Completions route will log the label as a prompt, where it logged nothing before.