Skip to content

OpenAI: Missing additionalProperties: false in tool parameters when strict mode is enabled #940

@Frostech0

Description

@Frostech0

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions