Skip to content

fix: remove Required on Optional field - #2576

Closed
truongvan wants to merge 1 commit into
openai:mainfrom
truongvan:patch-1
Closed

truongvan wants to merge 1 commit into
openai:mainfrom
truongvan:patch-1

Conversation

@truongvan

Copy link
Copy Markdown
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Additional context & links

@truongvan
truongvan requested a review from a team as a code owner August 21, 2025 13:18
@karpetrosyan karpetrosyan reopened this Oct 16, 2025
@jnohclee-rgb

Copy link
Copy Markdown

AI-assisted independent offline corroboration at 0bbf528ba3ba92d1632a7552838bcaaca6eb440e, against its parent e328fb4d79badc7ca28a1f599a56ab43eb420363. Five fictional FunctionToolParam payloads separate required key presence, nullable values and runtime defaults:

strict value Pydantic TypeAdapter before TypeAdapter on this head
omitted rejected accepted
null accepted accepted
true / false accepted accepted
invalid string rejected rejected

The actual SDK maybe_transform preserves each supplied dictionary identically on both sources, including omitted strict staying absent and explicit null staying null. Removing Required corrects the local annotation for key presence; it neither injects the documented default nor changes request transformation or adds runtime validation. A regression test for omitted strict, with null/bool controls, would make that intended scope explicit.

Scope: TypeAdapter is an independent annotation checker, not SDK request validation; maybe_transform preserves even the invalid string. No provider acceptance/default claim, endpoint calls or full SDK suite. Python3.14/Pydantic2.13.5, shared modern dependencies with archived sources; network denied by sandbox-exec.

Standalone reproducer
import json
from pydantic import TypeAdapter
from openai.types.responses.function_tool_param import FunctionToolParam
from openai._utils import maybe_transform
rows=[]
for label,value in [('omitted','OMIT'),('null',None),('true',True),('false',False),('invalid','not-bool')]:
 obj={'type':'function','name':'fictional','parameters':{'type':'object'}}
 if label!='omitted':obj['strict']=value
 try:TypeAdapter(FunctionToolParam).validate_python(obj);valid=True
 except Exception:valid=False
 rows.append({'case':label,'adapter_accepts':valid,'transformed':maybe_transform(obj,FunctionToolParam)})
print(json.dumps(rows))

@marcuswood-oai

Copy link
Copy Markdown
Contributor

Thanks for catching this typing mismatch. The API lets callers omit both strict and parameters, and FunctionToolParam currently marks both as required. I’ll close this patch and follow up on the schema in #4350 so the generated type reflects both fields correctly.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants