-
-
Notifications
You must be signed in to change notification settings - Fork 278
Open
Description
Description
When using tools with OpenAI's strict mode enabled, the API returns a 400 error because additionalProperties: false is not included in the tool's parameter schema.
OpenAI's function calling documentation explicitly requires additionalProperties: false at every level of the parameter object when strict mode is active.
Reproduction
Using the tool definition from the Prism docs — OpenAI provider ("Combining Tools with Structured Output"):
$weatherTool = Tool::as('get_weather')
->for('Get current weather for a location')
->withStringParameter('location', 'The city and state')
->using(fn (string $location): string => "Weather in {$location}: 72°F, sunny")
->withProviderOptions([
'strict' => true,
]);
$response = Prism::structured()
->using('openai', 'gpt-4o')
->withSchema($schema)
->withTools([$weatherTool])
->withMaxSteps(3)
->withPrompt('What is the weather in San Francisco and should I wear a coat?')
->asStructured();Error
OpenAI Error [400]: invalid_request_error - Invalid schema for function 'get_weather': In context=(), 'additionalProperties' is required to be supplied and to be false.
Root Cause
In src/Providers/OpenAI/Maps/ToolMap.php, the parameter schema is built as:
'parameters' => [
'type' => 'object',
'properties' => $tool->parametersAsArray(),
'required' => $tool->requiredParameters(),
],When strict is set to true, OpenAI requires additionalProperties: false to be present in the schema, but Prism does not add it.
Suggested Fix
Add additionalProperties: false conditionally when strict mode is enabled:
'parameters' => [
'type' => 'object',
'properties' => $tool->parametersAsArray(),
'required' => $tool->requiredParameters(),
...($tool->providerOptions('strict') ? [
'additionalProperties' => false,
] : []),
],Environment
- Prism version: v0.99.21
- PHP version: 8.4.1
- Provider: OpenAI (gpt-4o)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels