Skip to content

@tanstack/ai-openrouter: optional structured output fields are rewritten as nullable but rejected by original schema validation #731

@DrewHoo

Description

@DrewHoo

TanStack AI version

0.24.0

Framework/Library version

@tanstack/ai-openrouter 0.11.0

Describe the bug and the steps to reproduce it

  1. User provides a Standard Schema where a field is optional.
  2. TanStack converts it to JSON Schema.
  3. OpenRouter adapter rewrites optional fields into required + nullable for strict OpenAI/OpenRouter compatibility.
  4. Model returns null for that field, which the provider schema allowed.
  5. TanStack validates the result against the original Standard Schema, which rejects null.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/dkxh99pz?file=package.json

Screenshots or Videos (Optional)

Image

Do you intend to try to help solve this bug with your own PR?

Maybe, I'll investigate and start debugging

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions