Skip to content

fix(schemas): reject non-positive max_tokens and n at the schema boundary - #103

Open
antodeg wants to merge 1 commit into
Continuum-AI-Corp:mainfrom
antodeg:fix/schemas-positive-int-guards
Open

antodeg wants to merge 1 commit into
Continuum-AI-Corp:mainfrom
antodeg:fix/schemas-positive-int-guards

Conversation

@antodeg

@antodeg antodeg commented Sep 14, 2026

Copy link
Copy Markdown

Orca-Code-Review — push 1

Severity Count
P0 0
P1 0
P2 0
P3 0

✅ no blocking findings

What

max_tokens=0 and n=0 currently pass validation and reach the upstream provider, which rejects them with a confusing 400. Same for temperature values outside the [-2.0, 2.0] range.

Pydantic now fails closed with a clear validation error before the request reaches the routing layer.

Changes

  • max_tokens: Field(ge=1) — zero or negative token budgets are meaningless
  • n: Field(ge=1) — zero choices to return is not a valid request
  • temperature: Field(ge=-2.0, le=2.0) — matches the accepted range

All fields remain optional (None still means use the provider default).

Tests

12 new tests covering zero, negative, positive, and None cases for each guarded field.

…dary

max_tokens=0 and n=0 are meaningless — zero tokens to generate, zero
choices to return — and most upstream providers reject them with a
confusing 400 that leaks through to the client. Pydantic now fails
closed with a clear validation error before the request reaches the
routing layer.

Also clamps temperature to [-2.0, 2.0] to match the OpenAI / Anthropic
accepted range and reject accidental outliers (e.g. a slider widget
that lets the user drag past 2.0).

Tests cover the zero, negative, positive, and None cases for each
guarded field.

@orcacode-review orcacode-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐳 OrcaCode Review

No findings — nothing to flag in this PR. Great work!

OrcaCode Review — Route Smarter. Ship Safer. Spend Less.
Engine-reported: 358 calls · 22.2M tokens · 98% cached

❤️ Share · Install OrcaCode Review

Free on GitHub — the review runs on your own OrcaRouter key. If it helped, a shout-out goes a long way.

Share: X · Reddit · LinkedIn
Follow: X · Discord · LinkedIn · OrcaRouter

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