Skip to content

fix: preserve null types in tool parameter schemas for LLM - #4579

Merged
lucasgomide merged 7 commits into
mainfrom
lg-preserve-null-types-tools
Feb 26, 2026
Merged

fix: preserve null types in tool parameter schemas for LLM#4579
lucasgomide merged 7 commits into
mainfrom
lg-preserve-null-types-tools

Conversation

@lucasgomide

Copy link
Copy Markdown
Contributor

Tool parameter schemas were stripping null from optional fields via generate_model_description, forcing the LLM to provide non-null values for fields.
Adds strip_null_types parameter to generate_model_description and passes False when generating tool schemas, so optional fields keep anyOf: [{type: T}, {type: null}]

Tool parameter schemas were stripping null from optional fields via
generate_model_description, forcing the LLM to provide non-null values
for fields.
Adds strip_null_types parameter to generate_model_description and passes False when generating tool
schemas, so optional fields keep anyOf: [{type: T}, {type: null}]
Comment thread lib/crewai/src/crewai/utilities/pydantic_schema_utils.py Outdated

@greysonlalonde greysonlalonde left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just ensure you test on native tool calling for anthropic and openai, otherwise these may result in validation errors

@lucasgomide

lucasgomide commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

Just ensure you test on native tool calling for anthropic and openai, otherwise these may result in validation errors

@greysonlalonde I've already tested it.. everything works well. I can share examples if you'd like

@greysonlalonde

Copy link
Copy Markdown
Contributor

Just ensure you test on native tool calling for anthropic and openai, otherwise these may result in validation errors

@greysonlalonde I've already tested it.. everything works well. I can share examples if you'd like

Nope, good with me. I think accept @gabemilani 's nit, then gtg 👍

Co-authored-by: Gabe Milani <gabriel@crewai.com>
@lucasgomide

Copy link
Copy Markdown
Contributor Author

Just ensure you test on native tool calling for anthropic and openai, otherwise these may result in validation errors

@greysonlalonde I've already tested it.. everything works well. I can share examples if you'd like

Nope, good with me. I think accept @gabemilani 's nit, then gtg 👍

done!

@greysonlalonde greysonlalonde left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasgomide
lucasgomide merged commit 09e3b81 into main Feb 26, 2026
44 checks passed
@lucasgomide
lucasgomide deleted the lg-preserve-null-types-tools branch February 26, 2026 16:51
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.

4 participants