Skip to content

fix: coordinates z.tuple breaks OpenRouter/Azure structured output#13

Open
weareu wants to merge 3 commits intounitedbyai:mainfrom
wyobi:fix/openrouter-tuple-schema
Open

fix: coordinates z.tuple breaks OpenRouter/Azure structured output#13
weareu wants to merge 3 commits intounitedbyai:mainfrom
wyobi:fix/openrouter-tuple-schema

Conversation

@weareu
Copy link
Copy Markdown

@weareu weareu commented Mar 24, 2026

Problem

Using DroidClaw with OpenRouter (or any Azure-backed provider) fails with:

AI_APICallError: [Azure] Invalid schema for response_format 'response':
[{'type': 'number'}, {'type': 'number'}] is not of type 'object', 'boolean'

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()]) with z.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

  • OpenRouter → anthropic/claude-sonnet-4-6 (was failing, now works)
  • OpenRouter → openai/gpt-4o (was failing, now works)

weareu added 3 commits March 24, 2026 10:14
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.
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.

1 participant