Skip to content

Bug: Schema guard rejects integral JSON numbers written with a decimal point #2017

Backlog

Description

@Twiink

Component

OpenLIT Python SDK

What happened?

A schema with an integer attempts field rejects {"attempts":1.0} as a schema mismatch, although it represents the same JSON integer as 1. The real jsonschema validator accepts the same data. Valid model output is denied because of numeric spelling.

Steps to reproduce

On main at 463a1c1, run:

import json
import jsonschema
from openlit import Schema
from openlit.guard._base import GuardAction
schema={'type':'object','properties':{'attempts':{'type':'integer'}}}
value='{"attempts":1.0}'
jsonschema.validate(json.loads(value),schema)
result=Schema(schema=schema).evaluate(value)
print(json.dumps({'json_schema_accepts':True,'guard_action':result.action,'explanation':result.explanation}))
assert result.action==GuardAction.ALLOW

Actual output is recorded by the assertions. No provider requests are needed.

Expected behavior

Accept finite numeric values with a zero fractional part as JSON Schema integers, while rejecting fractional values, booleans and strings.

Environment

Python 3.12.14, OpenLIT SDK 1.45.0 from current main, OpenTelemetry SDK 1.45.2, Linux.

Additional context

The JSON Schema numeric type reference explicitly accepts 1.0 as an integer: https://json-schema.org/understanding-json-schema/reference/numeric#integer . Checked all-state Schema numeric work, including #1696 (booleans) and #1998 (union types); neither permits integral floats.

Investigation and execution used OpenAI Codex assistance. I can prepare a focused fix with regression tests.

  • I searched existing issues and did not find a duplicate
  • Yes, I am willing to submit a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions