Skip to content

Google AI API does not allow the additionalProperties key for response schemas #17

@dkotter

Description

@dkotter

If I'm using the AI Client to set a JSON response schema, example wp_ai_client_prompt( $prompt )->as_json_response( $this->suggestions_schema() ), the schema I set has additionalProperties keys, which is required to make that work with OpenAI.

This then causes issues when using this Google Provider, you'll end up with errors like Bad Request (400) - Invalid JSON payload received. Unknown name "additionalProperties" at 'generation_config.response_schema.properties[0].value.items': Cannot find field.

In debugging this, it seems Google does not support the additionalProperties key and in fact there's already code in place within this Provider to remove that from function declarations, see

// The Google AI API does not allow the `additionalProperties` key for function parameters.
$data['parameters'] = $this->removeAdditionalPropertiesKey($data['parameters']);

I think we'll want to run this same code when processing the JSON response schema and it may need extended to support removing this key from nested items.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions