Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: Apply strict JSON schema validation in FunctionTool constructor#1041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

habema
Copy link
Contributor

Summary

Fixes an issue where directly createdFunctionTool objects fail with OpenAI's Responses API due to missingadditionalProperties: false in the JSON schema, while the@function_tool decorator works correctly.

Problem

The documentation example for creatingFunctionTool objects directly fails with:

Error code: 400 - {'error': {'message': "Invalid schema for function 'process_user': In context=(), 'additionalProperties' is required to be supplied and to be false.", 'type': 'invalid_request_error', 'param': 'tools[0].parameters', 'code': 'invalid_function_parameters'}}

This creates an inconsistency betweenFunctionTool and@function_tool behavior, both of which havestrict_json_schema=True by default.

Solution

  • Added__post_init__ method toFunctionTool dataclass
  • Automatically appliesensure_strict_json_schema() whenstrict_json_schema=True
  • Makes behavior consistent with@function_tool decorator
  • Maintains backward compatibility

Testing

The fix can be verified by running the reproduction case from the issue:

fromtypingimportAnyfrompydanticimportBaseModelfromagentsimportRunContextWrapper,FunctionTool,Agent,RunnerclassFunctionArgs(BaseModel):username:strage:intasyncdefrun_function(ctx:RunContextWrapper[Any],args:str)->str:parsed=FunctionArgs.model_validate_json(args)returnf"{parsed.username} is{parsed.age} years old"# This now works without manual ensure_strict_json_schema() calltool=FunctionTool(name="process_user",description="Processes extracted user data",params_json_schema=FunctionArgs.model_json_schema(),on_invoke_tool=run_function,)agent=Agent(name="Test Agent",instructions="You are a test agent",tools=[tool])result=Runner.run_sync(agent,"Process user data for John who is 30 years old")

salah9003 reacted with thumbs up emoji
@habema
Copy link
ContributorAuthor

Linked Issue:#992

@seratchseratch added enhancementNew feature or request feature:core labelsJul 10, 2025
Copy link
Member

@seratchseratch left a comment

Choose a reason for hiding this comment

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

LGTM

@seratchseratch requested a review fromrm-openaiJuly 10, 2025 07:41
@rm-openairm-openai merged commitde8accc intoopenai:mainJul 18, 2025
5 checks passed
@salah9003
Copy link

من هنا إلى الأعلى 👍🏿 👍🏿

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@seratchseratchseratch approved these changes

@rm-openairm-openairm-openai approved these changes

Assignees
No one assigned
Labels
enhancementNew feature or requestfeature:core
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@habema@salah9003@seratch@rm-openai

[8]ページ先頭

©2009-2025 Movatter.jp