Skip to content

fix: sanitize required fields in tool schemas for Gemini compatibility#64284

Merged
steipete merged 2 commits into
openclaw:mainfrom
xxxxxmax:fix/sanitize-required-fields-gemini-refresh
Apr 10, 2026
Merged

fix: sanitize required fields in tool schemas for Gemini compatibility#64284
steipete merged 2 commits into
openclaw:mainfrom
xxxxxmax:fix/sanitize-required-fields-gemini-refresh

Conversation

@xxxxxmax

@xxxxxmax xxxxxmax commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Gemini-backed providers reject tool schemas when a required entry does not correspond to a declared property. In practice this shows up after schema cleanup and union flattening paths leave behind phantom required keys, which can trigger Gemini 400s while other providers tolerate the same payload.

This change keeps the fix scoped to the Gemini cleanup path:

  • add sanitizeRequiredFields() in src/agents/schema/clean-for-gemini.ts
  • filter required against declared own properties before returning cleaned Gemini schemas
  • drop required entirely when no valid entries remain
  • preserve non-Gemini behavior for flattened tool schemas
  • avoid inherited-property false positives like toString

Test plan

  • OPENCLAW_LOCAL_CHECK=0 pnpm test src/agents/pi-tools.schema.test.ts
  • OPENCLAW_LOCAL_CHECK=0 pnpm test src/agents/schema/clean-for-gemini.test.ts

@greptile-apps

greptile-apps Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a sanitizeRequiredFields() helper in the Gemini schema-cleaning path that filters required array entries to only those with a declared own property in properties, dropping the array entirely when no valid entries remain. It is applied at every exit point of cleanSchemaForGeminiWithDefs (post-union-flattening and the plain-object path), and is gated exclusively to the Gemini provider via the existing cleanSchemaForGemini call-chain, so non-Gemini schemas are unaffected. The new tests cover the key cases well: phantom keys, all-valid keys, all-phantom keys, inherited prototype keys, nested objects, and the non-Gemini passthrough.

Confidence Score: 5/5

Safe to merge — fix is scoped, well-tested, and doesn't affect non-Gemini providers.

No P0 or P1 issues found. The sanitizeRequiredFields helper is logically correct, uses Object.hasOwn to avoid prototype-key false positives, and mutates only freshly-created objects so callers are never surprised. Non-Gemini behavior is explicitly preserved and tested.

No files require special attention.

Reviews (1): Last reviewed commit: "fix: sanitize required fields in tool sc..." | Re-trigger Greptile

@steipete
steipete force-pushed the fix/sanitize-required-fields-gemini-refresh branch from b6671b1 to 863c3f5 Compare April 10, 2026 13:54
@steipete
steipete force-pushed the fix/sanitize-required-fields-gemini-refresh branch from 863c3f5 to 0f26da9 Compare April 10, 2026 13:59
@steipete
steipete force-pushed the fix/sanitize-required-fields-gemini-refresh branch from 0f26da9 to 3d2cda5 Compare April 10, 2026 14:01
@steipete
steipete merged commit fe1fd05 into openclaw:main Apr 10, 2026
9 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • Gate: pnpm check; pnpm test src/agents/schema/clean-for-gemini.test.ts src/agents/pi-tools.schema.test.ts src/plugin-sdk/provider-tools.test.ts; pnpm build
  • Full pnpm test was attempted locally and hit unrelated timeout/env-sensitive failures across non-touched shards under high parallelism.
  • Land commit: 3d2cda5
  • Merge commit: fe1fd05

Thanks @xxxxxmax!

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

Labels

agents Agent runtime and tooling size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants