Skip to content

fix: flatten geospatialQueryTool schema for OpenAI-compatible endpoints#620

Open
itsautomata wants to merge 1 commit into
QueueLab:mainfrom
itsautomata:fix/grok-multimodal-tool-schema
Open

fix: flatten geospatialQueryTool schema for OpenAI-compatible endpoints#620
itsautomata wants to merge 1 commit into
QueueLab:mainfrom
itsautomata:fix/grok-multimodal-tool-schema

Conversation

@itsautomata
Copy link
Copy Markdown
Contributor

@itsautomata itsautomata commented May 26, 2026

This PR fixes the Grok multimodal failure caused by xAI rejecting anyOf in tool parameter schemas.

Key Changes

  • lib/schema/geospatial.tsx: flatten geospatialQuerySchema with optional fields. Per-queryType requirements moved into the queryType description.
  • lib/agents/tools/geospatial.tsx: add runtime guard for required fields (search, geocode, reverse, directions, distance, map), replacing the parse-time field enforcement.

fixes #581

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 26, 2026

@itsautomata is attempting to deploy a commit to the QCX-MAIN Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Walkthrough

Geospatial schema is refactored from a discriminated union to a flat object with optional fields, and the reverse geocoding tool is updated with explicit input validation for required coordinates.

Changes

Geospatial Tool & Schema Consolidation

Layer / File(s) Summary
Geospatial Query Schema Refactoring
lib/schema/geospatial.tsx
geospatialQuerySchema changes from a discriminated union with per-queryType required fields to a single flat z.object where queryType is the only required discriminant and other fields (query, location, coordinates, origin, destination, mode, radius, maxResults, includeMap) become optional with constraints and defaults. The GeospatialQuery type inferred from this schema now reflects the flat/optional structure instead of discriminated per-type shapes.
Reverse Geocoding Tool Input Validation
lib/agents/tools/geospatial.tsx
Reverse geocoding tool argument construction now explicitly validates that params.coordinates exists before accessing latitude and longitude, throwing a descriptive error if missing instead of allowing undefined access.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • QueueLab/QCX#220: Updates to geospatial tool argument handling for reverse and reliance on the GeospatialQuery schema type for the execute signature align directly with this PR's schema and validation changes.
  • QueueLab/QCX#195: Related updates to the same geospatial MCP tool implementation and execute flow impacted by the schema and validation changes in this PR.

Suggested labels

Review effort 3/5

Poem

🐰 A schema once branched like a tree with many paths,
Now stands as one flat, with fields that are paths!
The reverse query validates coordinates with care,
No more undefined surprises hiding there! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: flattening the geospatialQueryTool schema to resolve OpenAI-compatible endpoint compatibility issues, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR successfully addresses the XAI/Grok compatibility issue (#581) by removing anyOf-producing schemas and adding runtime validation for nested coordinates access.
Out of Scope Changes check ✅ Passed All changes are directly related to the PR objective of fixing XAI/Grok tool schema compatibility; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #581

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 26, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f1041769-5aba-4e23-8bb3-800912a767d7

📥 Commits

Reviewing files that changed from the base of the PR and between d0efce4 and 5bd0143.

📒 Files selected for processing (2)
  • lib/agents/tools/geospatial.tsx
  • lib/schema/geospatial.tsx
📜 Review details
🔇 Additional comments (1)
lib/agents/tools/geospatial.tsx (1)

351-354: LGTM!

Comment thread lib/schema/geospatial.tsx
@itsautomata itsautomata force-pushed the fix/grok-multimodal-tool-schema branch 2 times, most recently from 3e03207 to f1265f1 Compare May 26, 2026 19:17
xAI's /v1/chat/completions rejects `anyOf` in tool parameter schemas.
geospatialQuerySchema used `z.discriminatedUnion`, which zod compiles
to `anyOf`. Every researcher invocation involving Grok 400'd silently
causing a multimodal/model issue.

- flatten geospatialQuerySchema from discriminatedUnion to z.object
  with optional fields and per-queryType description; runtime
  behavior unchanged (execute() already used `as any` for branch-
  specific fields)
- add runtime guard for required fields (search, geocode, reverse,
  directions, distance, map), replacing the parse-time field enforcement
@itsautomata itsautomata force-pushed the fix/grok-multimodal-tool-schema branch from f1265f1 to 845e5e1 Compare May 26, 2026 19:18
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
qcx Ready Ready Preview, Comment May 28, 2026 8:08am

@ngoiyaeric
Copy link
Copy Markdown
Collaborator

ngoiyaeric commented May 28, 2026

@itsautomata did you fix the xai_latest endpoint functionality with this pull request? what model did you test this pull request with?

@itsautomata
Copy link
Copy Markdown
Contributor Author

@ngoiyaeric this PR is complementary to #603 (but the fix applies independently) as it doesn't touch the xAI endpoint but the layer below model selection (the source problem was the schema structure).
tested on grok-4.3 and grok-4.2

@ngoiyaeric
Copy link
Copy Markdown
Collaborator

@itsautomata does the query type refractory improve the system's capability to classify the prompt for the geospatial tool? Does it respond to the query for geospatial function?

@itsautomata
Copy link
Copy Markdown
Contributor Author

@ngoiyaeric no visible or measured classification improvement I can testify for, but it fixes the xAI bug: now, models with strict schema validation like xAI (and any future provider with similar requirements) work the same as Gemini does today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update XAI model

3 participants