Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't working
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
Under the gpt5 model, the completion interface cannot utilize the custom tool's large capability
I have confirmed multiple times that my format meets the API interface requirements, and the API interface is: https://platform.openai.com/docs/api-reference/chat/create#chat -create-tools-custom-tool-custom-format
The interface response result is: Error code: 400 - {'error': {'message': 'Invalid param', 'type': 'invalid_request_error', 'param': 'c44c810b-15b6-4c62-8e6d-1b8ee2ceece8', 'code': 'param_error'}}
But it is unclear which field is the problem and how to fix it. Please provide the correct usage method
To Reproduce
Run the code
Code snippets
definition = """
start: expr
expr: term (SP ADD SP term)* -> add
| term
term: factor (SP MUL SP factor)* -> mul
| factor
factor: INT
SP: " "
ADD: "+"
MUL: "*"
%import common.INT
"""
ebnf_description = "Creates valid Lark grammar."
def custom_tool_ebnf_grammar_1():
return {
"type": "custom",
"custom": {
"name": "ebnf_grammar",
"description": ebnf_description,
"format": {
"type": "grammar",
"grammar": {
"syntax": "lark",
"definition": definition,
}
},
}
}
def custom_tool_ebnf_grammar_2():
return {
"type": "custom",
"custom": {
"name": "ebnf_grammar",
"description": ebnf_description,
"format": {
"type": "grammar",
"syntax": "lark",
"definition": definition,
},
}
}
def custom_tool_ebnf_grammar_3():
return {
"type": "custom",
"name": "ebnf_grammar",
"description": ebnf_description,
"format": {
"type": "grammar",
"syntax": "lark",
"definition": definition,
},
}
client = OpenAI()
ebnf_query = "use the ebnf_grammar tool to add four plus four."
def test_completion_chat_ebnf_grammar_1():
print("===== start test_completion_chat_ebnf_grammar_1 ===== ")
response = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": ebnf_query}],
tools=[custom_tool_ebnf_grammar_1()],
parallel_tool_calls=False,
tool_choice="required"
)
print(response.choices[0].message.content)
print("===== end test_completion_chat_ebnf_grammar_1 ===== ")
def test_completion_chat_ebnf_grammar_2():
print("===== start test_completion_chat_ebnf_grammar_2 ===== ")
response = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": ebnf_query}],
tools=[custom_tool_ebnf_grammar_2()],
parallel_tool_calls=False,
tool_choice="required"
)
print(response.choices[0].message.content)
print("===== end test_completion_chat_ebnf_grammar_2 ===== ")
def test_completion_chat_ebnf_grammar_3():
print("===== start test_completion_chat_ebnf_grammar_3 ===== ")
response = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": ebnf_query}],
tools=[custom_tool_ebnf_grammar_3()],
parallel_tool_calls=False,
tool_choice="required"
)
print(response.choices[0].message.content)
print("===== end test_completion_chat_ebnf_grammar_3 ===== ")OS
macOS
Python version
Python 3.9
Library version
openai 1.108.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
thromel commentedon Dec 4, 2025
Thank you for reporting this issue. I've identified a bug in the library's type definitions for custom tools in the Chat Completions API.
The Problem
The
ChatCompletionCustomToolParamtype had incorrect nesting that didn't match the actual API structure. According to the official documentation, custom tools should use this flat structure:{ "type": "custom", "name": "tool_name", "description": "Tool description", "format": { "type": "grammar", "syntax": "lark", "definition": grammar_definition } }But the library's type definitions incorrectly expected extra nesting:
name,description,formatwere expected inside acustomobjectsyntax,definitionwere expected inside aformat.grammarobjectThe Correct Format
Based on your examples,
custom_tool_ebnf_grammar_3()has the correct structure (closest to the API spec):This matches the Responses API's
CustomToolParamstructure, which is correct.Fix
The
ChatCompletionCustomToolParamtype definition needs to be updated to match theCustomToolParamstructure from the Responses API (which has the correct format). The fix is to remove the extra nesting insrc/openai/types/chat/chat_completion_custom_tool_param.py.Note: The "Invalid param" error with a UUID in the
paramfield suggests the actual validation error is happening on the API side. Ifcustom_tool_ebnf_grammar_3()is still failing, there may be additional constraints on the grammar definition itself - try a simpler grammar to rule out grammar parsing issues.RobertCraigie commentedon Dec 4, 2025
I think the issue is trying to access message content instead of tool calls?