Skip to content

fix(provider): sanitize tool schemas for strict validators#13738

Closed
sametakofficial wants to merge 1 commit intoanomalyco:devfrom
sametakofficial:fix/sanitize-tool-schemas
Closed

fix(provider): sanitize tool schemas for strict validators#13738
sametakofficial wants to merge 1 commit intoanomalyco:devfrom
sametakofficial:fix/sanitize-tool-schemas

Conversation

@sametakofficial
Copy link

@sametakofficial sametakofficial commented Feb 15, 2026

Fixes #13737
Related: #11413, #8184, #13618

Tool schemas have two issues that cause 400s on strict validators (Codex, Vertex AI, SGLang): optional properties missing from required when additionalProperties: false is set, and non-standard keywords ($schema, ref) from Zod meta.

Added a recursive sanitize() step in ProviderTransform.schema() that strips the bad keywords and ensures all properties are in required when additionalProperties is false. Runs before provider-specific transforms.

Tested against Codex and Vertex AI endpoints — both previously 400, now work. 6 new unit tests, all 104 existing tests pass.

Strip non-standard keywords ($schema, ref) and ensure all properties
are in required when additionalProperties is false.
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, I found two potentially related PRs that appear to be addressing similar schema sanitization issues:

  1. PR fix: sanitize tool JSON schemas for Claude API compatibility #13619: "fix: sanitize tool JSON schemas for Claude API compatibility"

    • Likely addressing similar schema validation issues for a different provider (Claude API)
  2. PR fix(google): sanitize unsupported JSON Schema keywords for Gemini API #13666: "fix(google): sanitize unsupported JSON Schema keywords for Gemini API"

    • Addressing schema keyword sanitization for the Google/Gemini API

These PRs seem to be part of a broader effort to sanitize tool schemas across different providers. They may be related work or even duplicative approaches to the same problem. I recommend checking if PR #13619 and #13666 are already merged or if they cover the same scope as PR #13738.

@rekram1-node
Copy link
Collaborator

Can u provide means to reproduce issue? You said before they 400, what tools were you passing?

@sametakofficial
Copy link
Author

No custom tools — this happens with a completely clean config. I set up a fresh opencode.json with just one provider (@ai-sdk/openai-compatible pointing to a strict OpenAI-compatible endpoint), no MCP, no plugins, no custom tools. First message I send → 400.

The endpoint rejects opencode's built-in question tool. Here's what gets sent:

{
  "type": "object",
  "properties": {
    "question": { "type": "string" },
    "header": { "type": "string" },
    "options": { "type": "array", ... },
    "multiple": { "type": "boolean" }
  },
  "required": ["question", "header", "options"],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema"
}

multiple is in properties but not in required, and additionalProperties is false. Strict validators won't accept that — every property needs to be in required if you're disabling additional properties.

The $schema and ref fields also cause issues on some endpoints.

Re: #13619 and #13666 — those are provider-specific fixes (Claude API and Gemini). This one runs in ProviderTransform.schema() before provider-specific transforms, so it catches the issue for all providers.

@sametakofficial
Copy link
Author

Closing in favor of #13823 which takes a better approach — wrapping optional properties with anyOf: [original, {type: "null"}] preserves the optional semantics while satisfying strict validators. Our fix just forced everything into required which changes the contract. Nice work @echoVic 👍

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.

Tool schemas cause 400 errors on strict validators (Codex, Vertex AI)

2 participants

Comments