fix: coordinates z.tuple breaks OpenRouter/Azure structured output#13
Open
weareu wants to merge 3 commits intounitedbyai:mainfrom
Open
fix: coordinates z.tuple breaks OpenRouter/Azure structured output#13weareu wants to merge 3 commits intounitedbyai:mainfrom
weareu wants to merge 3 commits intounitedbyai:mainfrom
Conversation
z.tuple([z.number(), z.number()]) serializes to JSON Schema with
items as an array: {"items": [{"type":"number"},{"type":"number"}]}
This is valid JSON Schema (tuple validation) but Azure-hosted
providers reject it — they only support single-schema items:
{"items": {"type":"number"}}
Error when using OpenRouter or Azure-backed providers:
[Azure] Invalid schema for response_format 'response':
[{'type': 'number'}, {'type': 'number'}] is not of type
'object', 'boolean'
Fix: z.array(z.number()).min(2).max(2) produces universally
compatible JSON Schema while enforcing the same [x, y] constraint.
z.record(z.string(), z.string()) generates a JSON Schema with
'propertyNames' which Azure rejects:
"In context=('properties', 'extras'), 'propertyNames' is not permitted"
Replace with z.object({}).passthrough() which produces a simple
additionalProperties schema that all providers accept.
OpenRouter proxies all structured output through Azure's JSON Schema validator, which rejects many valid JSON Schema features: - Tuple arrays (items as array) - minItems/maxItems > 1 - propertyNames (z.record) - Optional properties not in required Replace generateObject/streamObject with generateText/streamText for the OpenRouter provider. JSON structure is enforced via system prompt instructions instead of schema validation. Works universally across all models and providers behind OpenRouter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Using DroidClaw with OpenRouter (or any Azure-backed provider) fails with:
This happens because
z.tuple([z.number(), z.number()])serializes to JSON Schema tuple validation:{"type": "array", "items": [{"type": "number"}, {"type": "number"}]}Azure's structured output rejects tuple schemas — it only supports single-schema
items.Fix
Replace
z.tuple([z.number(), z.number()])withz.array(z.number()).min(2).max(2).This produces universally compatible JSON Schema:
{"type": "array", "items": {"type": "number"}, "minItems": 2, "maxItems": 2}Same runtime constraint (exactly 2 numbers), works with all providers.
Tested with
anthropic/claude-sonnet-4-6(was failing, now works)openai/gpt-4o(was failing, now works)