Skip to content

fix: validate routing limits on construction - #24

Merged
TheCoder30ec4 merged 2 commits into
TheCoder30ec4:mainfrom
bhuvan-01:codex/validate-limits
Sep 24, 2026
Merged

TheCoder30ec4 merged 2 commits into
TheCoder30ec4:mainfrom
bhuvan-01:codex/validate-limits

Conversation

@bhuvan-01

Copy link
Copy Markdown
Contributor

What does this change?

Fixes #9.

Limits(output_tokens=-5, max_cost_usd=-1) previously succeeded, letting invalid limits reach model filtering. Validate the arguments in Limits.__post_init__ and raise a field-specific ValueError immediately.

Require a positive integer output count and an optional nonnegative numeric budget. Reject booleans, invalid types, and NaN while preserving the defaults and zero budgets. Add regression tests and document the behavior in the README and changelog.

Related: #21 addresses the same issue. This implementation also covers the integer requirement, invalid types, and NaN, with boundary tests and user-facing documentation. Happy to consolidate with #21 if that is easier to review.

How was it tested?

On Windows with Python 3.13.3, using the pip/venv setup supported by CONTRIBUTING.md:

  • Before the fix, the new invalid-input tests failed in 14 subcases because no ValueError was raised.
  • python -m pytest -q: 69 passed, 22 subtests passed.
  • python -m ruff check .: passed.
  • python -m ruff format --check .: passed; all 14 Python files formatted.
  • git diff --check: passed.

Checklist

  • Full test suite passes locally (pip/venv equivalent of uv run pytest).
  • Ruff lint and formatting checks pass.
  • Tests added for the new behavior.
  • README and CHANGELOG updated.
  • No API keys or .env contents in the diff.

Prepared with AI assistance. The tests and checks listed above were executed locally.

@TheCoder30ec4
TheCoder30ec4 merged commit 65b1ee5 into TheCoder30ec4:main Sep 24, 2026
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.

Limits accepts negative or zero values without complaint

2 participants