Skip to content

Use parametersJsonSchema for function declarations and preserve Gemini call IDs - #51

Merged
gziolo merged 3 commits into
trunkfrom
fix/google-function-schemas
Oct 19, 2026
Merged

gziolo merged 3 commits into
trunkfrom
fix/google-function-schemas

Conversation

@gziolo

@gziolo gziolo commented Oct 16, 2026

Copy link
Copy Markdown
Member

What?

Fixes #50.
Fixes #33.
Supersedes #45 and #35.

This PR builds on the commits from #45 by @superdav42 and addresses the review feedback from @saarnilauri.

  • Send function input schemas through the Google parametersJsonSchema field instead of the legacy parameters field.
  • Keep standard JSON Schema keywords such as uniqueItems, additionalProperties, type unions and boolean enum values.
  • Always send schema maps such as properties, $defs, definitions and patternProperties as JSON objects. This covers empty maps and maps with numeric keys like '0', which PHP would otherwise encode as lists. Empty sub-schemas are sent as {}.
  • Build each function declaration from known fields only (name, description, parametersJsonSchema). Newer fields like annotations from php-ai-client 1.5.0 are not sent to Google.
  • Keep Gemini function call IDs when parsing responses and send them back in continuation requests.

Why?

The legacy parameters field only accepts a subset of OpenAPI. Google rejects the whole request when one tool uses an unsupported keyword. For example, the core/users-query ability failed because of uniqueItems and "enum": [true].

PHP encodes an empty array as []. Google expects an object for properties, so it returns 400 value for properties at top-level must be an object. One ability with no parameters was enough to break every request that included tools.

Google also rejects unknown fields in function declarations. php-ai-client 1.5.0 adds annotations to FunctionDeclaration::toArray(), so forwarding that array as-is would break requests once annotations are used.

Testing

  • composer test passes with php-ai-client 1.5.0 and 1.3.1. The annotations test is skipped on 1.3.1.
  • composer lint passes (PHPCS and PHPStan).
  • New tests cover the core/users-query cases, empty and nested empty schemas, numeric property names, leaving out annotations, and missing, null or invalid function call IDs.

Follow-up

Structured output still uses responseSchema with the same OpenAPI subset. Switching it to responseJsonSchema will be a separate PR.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code, Codex
Model(s): Claude Opus 5.5, GPT-6-Astra
Used for: Reviewing #45 and its feedback, drafting the schema normalization, tests and this description. I reviewed and edited the final code and tests and take responsibility for them.

superdav42 and others added 3 commits October 16, 2026 13:56
Build function declarations from known fields only, so newer fields
like `annotations` from php-ai-client 1.5.0 are not sent to Google.

Send schema maps such as `properties` and `$defs` as JSON objects.
This fixes empty maps and maps with numeric keys, which PHP encodes
as JSON lists. Empty sub-schemas are sent as `{}` too.

Simplify function call ID handling and add tests for missing,
null and invalid IDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gziolo
gziolo requested a review from a team October 16, 2026 12:19
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: superdav42 <superdav42@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: saarnilauri <laurisaarni@git.wordpress.org>
Co-authored-by: Arkenon <arkenon@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@saarnilauri saarnilauri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for carrying on the work. This LGTM.

@gziolo
gziolo merged commit c5f20e8 into trunk Oct 19, 2026
14 checks passed
@gziolo
gziolo deleted the fix/google-function-schemas branch October 19, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants