OpenAI tool-call arguments should normalize on parse #4742
davidahmann
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem observed
OpenAI chat and responses parse paths currently hand back function-call arguments as raw JSON strings, while the other backends in this repo already normalize equivalent tool-call payloads to mappings.
Why it matters operationally
That backend-specific envelope shape leaks into downstream logic and tests. Tool-call handling is supposed to be provider-agnostic at the framework boundary, but callers end up needing to special-case OpenAI responses or remember to re-parse arguments defensively. The inconsistency is small, but it undermines deterministic workflow behavior and makes backend swaps harder to reason about.
Minimal repro
argumentsfield is a JSON object string.Content.from_function_call(...).argumentsvalue.Fix approach
The change stays at the parse boundary. A helper normalizes provider arguments to a mapping when the payload is a JSON object, and the OpenAI chat/responses parsers use it immediately on ingest. That avoids changing outgoing provider payload formatting while still removing the internal shape mismatch that downstream code sees.
Validation evidence
uv run pytest packages/core/tests/openai/test_openai_chat_client.py::test_parse_tool_calls_from_openai_normalizes_json_object_arguments packages/core/tests/openai/test_openai_responses_client.py::test_response_content_creation_with_function_call packages/core/tests/openai/test_openai_responses_client.py::test_parse_response_from_openai_function_call_includes_status -m "not integration"passed.Open follow-up question for maintainers
Do you want the same normalization applied to any remaining Azure/OpenAI ingestion surfaces that intentionally preserve raw strings today?
Inspired by research context: CAISI publishes independent, reproducible AI agent governance research: https://caisi.dev
Beta Was this translation helpful? Give feedback.
All reactions