Skip to content

Fix Google VertexAI chat completion tool call args for non-string values - #156665

Merged
seanhandley merged 5 commits into
mainfrom
fix/googlevertexai-tool-call-non-string-args-156644
Aug 13, 2026
Merged

seanhandley merged 5 commits into
mainfrom
fix/googlevertexai-tool-call-non-string-args-156644

Conversation

@seanhandley

Copy link
Copy Markdown
Contributor

Summary

Fixes #156644.

GoogleVertexAiUnifiedChatCompletionRequestEntity#jsonStringToMap used parser.mapStrings() which calls parser.text() on each map value. When a tool call argument value is a JSON array, number, or nested object (e.g. {"indices": ["foo"]}) the parser throws Expected text but found START_ARRAY.

Change parser.mapStrings() → parser.map() (returning Map<String, Object>) so arbitrary JSON argument values are preserved and serialized correctly into the Vertex AI functionCall.args Struct field.

Changes

  • GoogleVertexAiUnifiedChatCompletionRequestEntity.java: one-line change — mapStrings() → map(), return type Map<String,String> → Map<String,Object>
  • GoogleVertexAiUnifiedChatCompletionRequestEntityTests.java: adds testParseFunctionCallWithNonStringArgValues covering array and number argument values

Test plan

  • ./gradlew :x-pack:plugin:inference:test --tests "org.elasticsearch.xpack.inference.services.googlevertexai.request.completion.GoogleVertexAiUnifiedChatCompletionRequestEntityTests"
  • Existing testParseFunctionCallWithBadJson still expects ParsingException for non-object top-level JSON (unchanged behaviour)

🤖 Generated with Claude Code

@elasticsearchmachine elasticsearchmachine added v9.6.0 needs:triage Requires assignment of a team area label labels Aug 13, 2026
jsonStringToMap used parser.mapStrings() which calls parser.text() on each
value, throwing when the value is an array or number. Change to parser.map()
so arbitrary JSON argument values are preserved correctly when serialized
into the Vertex AI functionCall.args Struct field.
@seanhandley
seanhandley force-pushed the fix/googlevertexai-tool-call-non-string-args-156644 branch from e7ef0ec to 3cd73e2 Compare August 13, 2026 10:01
@seanhandley seanhandley added :SearchOrg/Inference Label for the Search Inference team Team:Search - Inference labels Aug 13, 2026
@github-actions

github-actions Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Preview links for changed docs

⏳ Building and deploying preview... View progress

This comment will be updated with preview links when the build is complete.

@seanhandley seanhandley self-assigned this Aug 13, 2026
@seanhandley
seanhandley requested a lite review from Copilot August 13, 2026 10:03
@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Aug 13, 2026
@elasticsearchmachine

Copy link
Copy Markdown
Collaborator

Pinging @elastic/search-inference-team (Team:Search - Inference)

@github-actions

Copy link
Copy Markdown
Contributor

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

Copilot AI 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.

Pull request overview

Fixes Google VertexAI chat_completion request serialization for tool calls whose arguments JSON contains non-string values (arrays, numbers, nested objects). This aligns the request builder with the OpenAI-compatible tool-calling spec and prevents request construction failures before the request is sent to Vertex AI.

Changes:

  • Parse tool-call arguments JSON with XContentParser#map() instead of mapStrings(), preserving non-string values.
  • Update the jsonStringToMap return type to Map<String, Object> accordingly.
  • Add a unit test covering array and numeric argument values to prevent regressions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/googlevertexai/request/completion/GoogleVertexAiUnifiedChatCompletionRequestEntity.java Switch tool-call args parsing from string-only maps to generic maps so arrays/numbers/objects serialize correctly.
x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googlevertexai/request/completion/GoogleVertexAiUnifiedChatCompletionRequestEntityTests.java Add regression test validating serialization of tool-call args containing arrays and numbers.
docs/changelog/156644.yaml Add changelog entry documenting the bug fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dimitris-athanasiou dimitris-athanasiou 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.

LGTM

@dimitris-athanasiou

Copy link
Copy Markdown
Contributor

Let's backport this to 9.5, 9.4, and 8.19. I'll add the labels.

@dimitris-athanasiou dimitris-athanasiou added auto-backport Automatically create backport pull requests when merged v8.19.21 v9.4.6 v9.5.2 labels Aug 13, 2026
@seanhandley
seanhandley disabled auto-merge August 13, 2026 16:05
@seanhandley
seanhandley merged commit 35d2cca into main Aug 13, 2026
37 of 38 checks passed
@seanhandley
seanhandley deleted the fix/googlevertexai-tool-call-non-string-args-156644 branch August 13, 2026 16:06
@seanhandley

Copy link
Copy Markdown
Contributor Author

Skipped the flaky serverless check and merged

@jonathan-buttner

Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
✅ 9.5
✅ 9.4
✅ 8.19

Questions ?

Please refer to the Backport tool documentation

elasticsearchmachine pushed a commit that referenced this pull request Aug 13, 2026
…ues (#156665) (#156699)

* Fix Google VertexAI tool call args serialization for non-string values

jsonStringToMap used parser.mapStrings() which calls parser.text() on each
value, throwing when the value is an array or number. Change to parser.map()
so arbitrary JSON argument values are preserved correctly when serialized
into the Vertex AI functionCall.args Struct field.

* Fix changelog area for 156644

(cherry picked from commit 35d2cca)

Co-authored-by: Sean Handley <seanhandley@users.noreply.github.com>
elasticsearchmachine pushed a commit that referenced this pull request Aug 13, 2026
…ing values (#156665) (#156701)

* Fix Google VertexAI chat completion tool call args for non-string values (#156665)

* Fix Google VertexAI tool call args serialization for non-string values

jsonStringToMap used parser.mapStrings() which calls parser.text() on each
value, throwing when the value is an array or number. Change to parser.map()
so arbitrary JSON argument values are preserved correctly when serialized
into the Vertex AI functionCall.args Struct field.

* Fix changelog area for 156644

(cherry picked from commit 35d2cca)

* Fixing class ref

---------

Co-authored-by: Sean Handley <seanhandley@users.noreply.github.com>
charlotte-hoblik added a commit that referenced this pull request Aug 18, 2026
The entry recorded pr: 156644, but 156644 is the issue number. The
change was made by PR #156665, backported here as #156699. Point pr:
at the PR and leave the issue reference intact.

Previously the note rendered a link to /pull/156644 alongside a
self-referencing "(issue: #156644)". This affects the 9.5.2 release
notes, which are bundled from this branch.

The filename is deliberately left as 156644.yaml rather than renamed
to match the PR: the 9.5.2 build candidate is cut from this branch
today, and BundleChangelogsTask adds changelogs from branch HEAD on
top of the BC tree without deleting removed files, so a rename after
the BC would list this fix twice in the release notes.
elasticsearchmachine pushed a commit that referenced this pull request Aug 18, 2026
…ues (#156665) (#156700)

* Fix Google VertexAI tool call args serialization for non-string values

jsonStringToMap used parser.mapStrings() which calls parser.text() on each
value, throwing when the value is an array or number. Change to parser.map()
so arbitrary JSON argument values are preserved correctly when serialized
into the Vertex AI functionCall.args Struct field.

* Fix changelog area for 156644

(cherry picked from commit 35d2cca)

Co-authored-by: Sean Handley <seanhandley@users.noreply.github.com>
ncordon pushed a commit to ncordon/elasticsearch that referenced this pull request Aug 24, 2026
…ues (elastic#156665)

* Fix Google VertexAI tool call args serialization for non-string values

jsonStringToMap used parser.mapStrings() which calls parser.text() on each
value, throwing when the value is an array or number. Change to parser.map()
so arbitrary JSON argument values are preserved correctly when serialized
into the Vertex AI functionCall.args Struct field.

* Fix changelog area for 156644
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :SearchOrg/Inference Label for the Search Inference team Team:Search - Inference v8.19.21 v9.4.6 v9.5.2 v9.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Inference] googlevertexai chat_completion fails on tool calls with non-string argument values: "Expected text but found START_ARRAY"

5 participants