fix: use provider-agnostic schema for non-OpenAI tool conversion (#4472)#4473
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
fix: use provider-agnostic schema for non-OpenAI tool conversion (#4472)#4473devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
Fixes #4472 — MCP tools (and any tool with args_schema) produced JSON schemas incompatible with Gemini and Bedrock/Anthropic because extract_tool_info() called generate_model_description() which applies OpenAI-specific transformations (additionalProperties: false, forcing all properties required, title fields). Added generate_tool_parameters_schema() that produces clean schemas without those provider-specific metadata fields. Updated extract_tool_info() to use it for the args_schema path. Co-Authored-By: João <joao@crewai.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: João <joao@crewai.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.
fix: use provider-agnostic schema for non-OpenAI tool conversion (#4472)
Summary
extract_tool_info()incommon.pycalledgenerate_model_description()when converting a tool'sargs_schemato parameters. That function applies OpenAI strict-mode transformations (additionalProperties: false, forcing all properties required,titleon every object) that Gemini and Bedrock reject.This PR adds
generate_tool_parameters_schema()— a new provider-agnostic path that:$ref/$defsanyOfnull unions (forOptionalfields)title,default, andadditionalPropertiesrequiredarray (does not force every property required)extract_tool_info()now calls this new function instead ofgenerate_model_description()for theargs_schemafallback path.Files changed:
lib/crewai/src/crewai/utilities/pydantic_schema_utils.py— added_strip_schema_metadata()andgenerate_tool_parameters_schema()lib/crewai/src/crewai/llms/providers/utils/common.py— switchedextract_tool_infoto use new functionlib/crewai/tests/utilities/test_tool_schema_compatibility.py— 24 new testsReview & Testing Checklist for Human
args_schemafallback inextract_tool_info()(line ~82 ofcommon.py). This path is only hit when the tool dict is in "direct format" (no"function"key), has no inline"parameters", and does have an"args_schema". Confirm MCP tools actually flow through this branch and not the"function"or"parameters"branches above it.defaultvalues: The helper removesdefaultfrom all properties recursively. Verify this doesn't cause issues for providers that can usefully consume defaults (e.g., OpenAI or Anthropic direct format). Note: this code path is only reached for theargs_schemafallback, not for tools that already supply inlineparameters._strip_schema_metadatamutates in-place: The helper doesschema.pop(key)on the passed dict. It's safe ingenerate_tool_parameters_schema(fresh dict frommodel_json_schema), but since it's a module-level function that tests import directly, consider whether it should defensively copy.gemini-2.5-flashand Bedrock Claude — this is the scenario from the bug report and cannot be fully validated by unit tests alone.Notes
generate_model_description) is unchanged and verified byTestOpenAISchemaUnchangedtests.