Repository navigation
Fix Google VertexAI chat completion tool call args for non-string values - #156665
Conversation
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.
e7ef0ec to
3cd73e2
Compare
🔍 Preview links for changed docs⏳ Building and deploying preview... View progress This comment will be updated with preview links when the build is complete. |
|
Pinging @elastic/search-inference-team (Team:Search - Inference) |
ℹ️ 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 overviewWhen to use applies_to tags:✅ At the page level to indicate which products/deployments the content applies to (mandatory) What NOT to do:❌ Don't remove or replace information that applies to an older version 🤔 Need help?
|
There was a problem hiding this comment.
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
argumentsJSON withXContentParser#map()instead ofmapStrings(), preserving non-string values. - Update the
jsonStringToMapreturn type toMap<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.
|
Let's backport this to 9.5, 9.4, and 8.19. I'll add the labels. |
|
Skipped the flaky serverless check and merged |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
…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>
…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>
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.
…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>
…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
Summary
Fixes #156644.
GoogleVertexAiUnifiedChatCompletionRequestEntity#jsonStringToMapusedparser.mapStrings()which callsparser.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 throwsExpected text but found START_ARRAY.Change
parser.mapStrings()→parser.map()(returningMap<String, Object>) so arbitrary JSON argument values are preserved and serialized correctly into the Vertex AIfunctionCall.argsStructfield.Changes
GoogleVertexAiUnifiedChatCompletionRequestEntity.java: one-line change —mapStrings()→map(), return typeMap<String,String>→Map<String,Object>GoogleVertexAiUnifiedChatCompletionRequestEntityTests.java: addstestParseFunctionCallWithNonStringArgValuescovering array and number argument valuesTest plan
./gradlew :x-pack:plugin:inference:test --tests "org.elasticsearch.xpack.inference.services.googlevertexai.request.completion.GoogleVertexAiUnifiedChatCompletionRequestEntityTests"testParseFunctionCallWithBadJsonstill expectsParsingExceptionfor non-object top-level JSON (unchanged behaviour)🤖 Generated with Claude Code