← Back to PRs

#23507: fix(tools): strip patternProperties from schemas for OpenAI-compatible providers

by long-pham open 2026-02-22 11:09 View on GitHub →
agents size: S
## Summary - TypeBox's `Type.Record(Type.String(), ...)` compiles tool parameter schemas with a `patternProperties` key, which most OpenAI-compatible APIs (e.g. RouteLLM) reject with HTTP 400 `"Validation Error: \"patternProperties\" - Extra inputs are not permitted"` - Add a recursive `stripPatternProperties()` helper in `normalizeToolParameters()` that removes `patternProperties` before the schema is sent to non-Anthropic, non-Gemini providers - Anthropic handles the field natively; Gemini already goes through the more aggressive `cleanSchemaForGemini()` path which covers this keyword ## Test plan - [ ] Run agent with RouteLLM model — `exec` tool (which has `env: Type.Record(...)`) no longer causes HTTP 400 - [ ] Verify Anthropic and Gemini providers are unaffected - [ ] Existing unit/e2e tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> Added a `stripPatternProperties()` helper function that recursively removes `patternProperties` from JSON schemas before sending them to OpenAI-compatible providers like RouteLLM. TypeBox's `Type.Record(Type.String(), ...)` generates schemas with `patternProperties`, which most OpenAI-compatible APIs reject. The fix applies only to non-Anthropic, non-Gemini providers - Anthropic handles the field natively, while Gemini already uses the more aggressive `cleanSchemaForGemini()` which removes this keyword. The implementation correctly: - Strips top-level `patternProperties` keys - Recursively processes nested schemas in `properties`, `items`, `anyOf`, `oneOf`, and `allOf` - Integrates cleanly into all three code paths in `normalizeToolParameters()` - Preserves existing behavior for Anthropic and Gemini providers <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is well-documented, follows existing code patterns, and correctly addresses the OpenAI-compatible provider issue. The recursive stripping logic appropriately handles all cases where `patternProperties` would appear in TypeBox-generated schemas. The fix is properly scoped to only affect non-Anthropic, non-Gemini providers, preserving existing behavior for those providers. - No files require special attention <sub>Last reviewed commit: 30d90c1</sub> <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs