Skip to content

fix(python-sdk): reject booleans for numeric schemas - #1696

Merged
AmanAgarwal041 merged 3 commits into
openlit:mainfrom
Harsh23Kashyap:ai/schema-bool-numeric
Nov 10, 2026
Merged

AmanAgarwal041 merged 3 commits into
openlit:mainfrom
Harsh23Kashyap:ai/schema-bool-numeric

Conversation

@Harsh23Kashyap

@Harsh23Kashyap Harsh23Kashyap commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1691.

bool subclasses int in Python, so the schema guard's isinstance check accepted JSON true and false for integer and number schemas. Reject booleans explicitly for numeric schemas while preserving normal numeric values and boolean schemas.

Focused tests cover both boolean literals against integer and number, numeric values including zero, and the valid boolean case. tests/test_guard_schema.py and tests/test_guard_pipeline.py: 26 passed.

This AI-generated change follows OpenLIT's contribution guidance; AI assistance is disclosed.

Summary by Sourcery

Ensure Python schema validation treats booleans as distinct from numeric types.

Bug Fixes:

  • Reject boolean values for integer and number schemas while continuing to accept valid numeric values and boolean schemas.

Tests:

  • Add focused schema guard coverage for boolean rejection, numeric acceptance including zero, and valid boolean schemas.

@sourcery-ai

sourcery-ai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implementation

Explicitly reject booleans for integer and number schemas because Python considers booleans instances of integers.

  • sdk/python/src/openlit/guard/schema.py L32-37

Tests

Cover boolean rejection for numeric schemas, acceptance of numeric values including zero, and acceptance of booleans by boolean schemas.

  • sdk/python/tests/test_guard_schema.py L1-32

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Automated title normalization could not complete. Please update this PR title manually using Conventional Commit format:

  • type: lowercase summary
  • type(scope): lowercase summary

Allowed types: feat, fix, docs, chore, refactor, test, ci, build, perf, style, or revert.

Examples: ci: fix automation workflows or fix(python): handle streaming responses. Keep the title at 120 characters or fewer.

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Oct 5, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@Harsh23Kashyap Harsh23Kashyap changed the title [AI] fix(python-sdk): reject booleans for numeric schemas fix(python-sdk): reject booleans for numeric schemas Oct 27, 2026
@Harsh23Kashyap

Copy link
Copy Markdown
Contributor Author

A note on the failing Normalize / Conventional title check: the workflow behind it (admin-pr-management.yml) only runs on the pull_request opened event, so this failure is from the title as it was when the PR was first opened. The current title matches the required pattern, but title edits do not retrigger the workflow, so the red check cannot clear by itself. Nothing in the PR content causes it.

@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit 31ecfd5

#1691 Bug: Schema guard accepts JSON booleans for numeric types · 3 of 3 met

# Requirement Status Notes
1 Reject JSON booleans for integer and number schemas, including object properties and array items. ✅ Met The validator rejects booleans for both numeric types, and its existing recursive validation applies the check to object properties and array items.
2 Allow zero for integer and number schemas. ✅ Met The added tests cover zero for both numeric schema types.
3 Continue accepting booleans for boolean schemas. ✅ Met The added test verifies that a boolean schema accepts true.

@AmanAgarwal041
AmanAgarwal041 merged commit 9e28954 into openlit:main Nov 10, 2026
6 of 7 checks passed
@github-actions

Copy link
Copy Markdown

Merged PR summary

  • Python SDK · Fixes — Reject boolean values for integer and number schemas so JSON booleans are not accepted as numeric, while valid numbers and boolean schemas continue to work.

Generated from the merged PR description and bounded, component-scoped file evidence. Release preparation reuses this validated summary.

This branch was previously deployed

1 inactive deployment
release-notes — 31ecfd52 Deployed Nov 10, 2026 by AmanAgarwal041 via Summarize / Merged pull request #268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Schema guard accepts JSON booleans for numeric types

2 participants