Skip to content

fix(llms): fall back to non-strict schemas for dict-valued fields - #10263

Open
aryansahai22 wants to merge 1 commit into
crewAIInc:mainfrom
aryansahai22:fix/dict-args-non-strict
Open

aryansahai22 wants to merge 1 commit into
crewAIInc:mainfrom
aryansahai22:fix/dict-args-non-strict

Conversation

@aryansahai22

Copy link
Copy Markdown

Related issue

Fixes #10262

Summary

generate_model_description() forced additionalProperties: false on every object and labelled the result strict: True. A dict[str, X] / Mapping field, which Pydantic emits as {"type": "object", "additionalProperties": <value schema>}, therefore became a closed object with no properties. Under OpenAI and Anthropic strict mode that schema admits exactly one value, {}, so a tool argument such as headers: dict[str, str] never received any keys, and a dict field on an output_pydantic / response_format model always came back empty. Nothing errored; the tool just ran with an empty dict.

Strict mode cannot express such a field at all (both vendors require additionalProperties: false on every object), so the fix sends these schemas non-strict with the value schema intact instead of "fixing" them by deleting it:

  • pydantic_schema_utils.allows_additional_properties() (new) reports whether any object in a schema allows additional properties. It walks the whole schema, including $defs, anyOf branches and array items, with the same cycle guard the neighbouring helpers use.
  • generate_model_description() computes strict from the raw Pydantic schema, only closes objects when strict, and returns the real value. JsonSchemaInfo.strict becomes bool. The OpenAI Responses text.format and Azure response_format paths already read this flag, so structured output with a dict field is now sent non-strict.
  • convert_tools_to_openai_schema() carries that flag instead of hard-coding "strict": True, which fixes the Anthropic and LiteLLM paths that read it.
  • The OpenAI Chat Completions and Anthropic tool converters check the schema before applying their strict sanitizers, so tools passed as plain dicts are covered too. Everything else keeps today's strict behavior: a tool or model without a dict field is still sent strict and closed exactly as before.

Before and after, for the tool in the issue:

// before
{"strict": true, "headers": {"additionalProperties": false, "type": "object", "properties": {}, "required": [], "description": "HTTP headers to send"}}
// after
{"strict": false, "headers": {"additionalProperties": {"type": "string"}, "type": "object", "title": "Headers", "description": "HTTP headers to send"}}

Verification

  • Tests added or updated for the changed behavior
    • tests/utilities/test_pydantic_schema_utils.py: TestAllowsAdditionalProperties (value schema, true, Optional[dict] inside anyOf, dict in array items, dict behind a $ref, closed objects, explicit false, cyclic input).
    • tests/utilities/test_converter.py: test_generate_model_description_dict_field now asserts the value schema is kept and strict is False (it previously only checked the flag was True); new test_generate_model_description_nested_dict_field.
    • tests/utilities/test_agent_utils.py: a BaseTool with headers: dict[str, str] is converted non-strict with its schema intact; a tool without a dict stays strict and closed.
    • tests/llms/openai/test_openai.py and tests/llms/anthropic/test_anthropic.py: a dict-argument tool is sent non-strict with the schema intact while a sibling tool stays strict and sanitized.
  • Relevant tests and quality checks pass locally
    • uv run ruff check lib/, uv run ruff format --check lib/, uv run mypy lib/
    • cd lib/crewai && uv run pytest tests/utilities tests/llms tests/agents tests/tools (3181 passed, 35 skipped, 4 xfailed)

Additional context

  • Non-strict tool parameters are sent as Pydantic emits them (including title keys), the same way the Responses API path already sends every tool. Gemini (parameters_json_schema) and Bedrock (inputSchema.json) pass the schema through, so they now receive the real dict schema instead of a closed empty object.
  • A model with model_config = ConfigDict(extra="allow") emits additionalProperties: true and is now also sent non-strict, since strict mode cannot honour it either. No bundled tool declares that on its args_schema.
  • The OpenAI Agents SDK adapter (openai_agent_tool_adapter.py) closes schemas on its own and is unchanged here.
  • This change was developed with an AI coding agent and reviewed by me; per CONTRIBUTING, please add the llm-generated label (I cannot set labels on this repo).

generate_model_description() forced additionalProperties=false on every
object, which turned a dict/Mapping field into a closed object with no
properties. OpenAI and Anthropic strict mode then admit exactly one value
for it, {}, so a tool argument such as headers: dict[str, str] never
received any keys and a dict field on an output_pydantic/response_format
model always came back empty, with no error anywhere.

Strict mode cannot express such a field at all, so detect it with the new
allows_additional_properties() and send the schema non-strict with its
value schema intact: generate_model_description() reports the real strict
value, convert_tools_to_openai_schema() carries it instead of hard-coding
True, and the OpenAI and Anthropic tool converters check the schema before
applying their strict sanitizers. Tools and models without such a field
are sent strict and closed exactly as before.

Fixes crewAIInc#10262
@strix-security

strix-security Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: Fixes tool and structured-output schemas so a `dict`/`Mapping` field keeps its value schema and the schema is sent non-strict instead of being closed to an empty object, carrying the real `strict` flag through the OpenAI, Anthropic and LiteLLM conversion paths.

Review summary

Reviewed the schema-strictness change across the four production files it touches: the new allows_additional_properties() walker, the strict computation in generate_model_description(), the flag propagation in convert_tools_to_openai_schema(), and the OpenAI Chat Completions / Anthropic tool converters that now skip their strict sanitizers for schemas containing a dict-valued field. I traced the loosened paths into the structured-output consumers (text.format, Azure response_format, output_pydantic), every other reader of the strict flag (LiteLLM, Gemini, Bedrock, Responses), and the tool-definition/description channels fed by remote MCP and A2A schemas, and checked whether the now-populatable dict arguments or the unvalidated argument replay in the Anthropic/Bedrock/Snowflake history formatters give a prompt-injection attacker anything new. No security vulnerability was confirmed: strict mode is a vendor-shape constraint rather than a validation gate here, model output is still re-validated against the Pydantic model, and no model-controlled dict keys reach a dangerous sink that the previous behaviour protected.

Review 1 on this PR · ad97292 · requested Dec 6 00:04 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] dict-typed tool arguments are sent as closed empty objects, so the model can only pass {}

1 participant