fix(anthropic_response): fail translation on malformed tool arguments (#550) - #874
Open
leseb wants to merge 1 commit into
Open
fix(anthropic_response): fail translation on malformed tool arguments (#550)#874leseb wants to merge 1 commit into
leseb wants to merge 1 commit into
Conversation
…praxis-proxy#550) When translating an OpenAI Chat Completions response into Anthropic Messages format, tool call arguments that were not a valid JSON-encoded object were silently replaced with an empty object (`{}`). That could cause an Anthropic client to execute a tool with missing or default parameters. Translation now fails instead of fabricating an executable `tool_use` block. Because upstream status headers are already committed by the time the body is parsed, the original upstream response is preserved unchanged rather than emitting a misleading error, which avoids accidental tool execution without inventing a semantically incorrect response. Adds unit, functional proxy, and controlled synthetic inference fixture coverage. Signed-off-by: Sébastien Han <seb@redhat.com>
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.
Summary
When translating an OpenAI Chat Completions response into Anthropic Messages format, tool-call arguments that were not a valid JSON-encoded object were silently replaced with an empty object (
{}), which could make an Anthropic client execute a tool with missing or default parameters. Translation now fails on malformed/non-object arguments instead of fabricating an executabletool_useblock, and because the upstream status headers are already committed by the time the body is parsed, the original upstream response is preserved unchanged rather than emitting a misleading200 OKerror. This is the smallest complete change: aResult-returning transform plus unit, functional proxy, and controlled synthetic inference-fixture coverage.Related issue
Closes #550
Validation
make lint— clippy, rustfmt, dependency, docs, example, andcheck-inferencegates all pass.make buildcargo test -p praxis-ai-apis --lib -- anthropic::to_openai::response— 21 passed, incl.invalid_tool_call_arguments_fail_transformationandnon_object_tool_call_arguments_fail_transformation.make test-inference-fixtures— coverage tests +all_inference_fixtures_replaypass.cargo test -p praxis-tests-integration --test suite anthropic_to_openai_preserves_response_with_malformed_tool_argumentsUnit tests
Integration or functional tests
make lintChecklist
anthropic/messages-to-openai.yamlexample with a new functional test.)Signed-off-bytrailer.Breaking changes
None. Previously a malformed tool-argument response produced a fabricated empty-input
tool_useblock; it now preserves the original upstream response so no validtool_useis invented. Valid responses are unaffected.