Skip to content

Bug: Schema JSON guard accepts non-JSON NaN and Infinity constants #1865

Open

Description

@WitBlue6

Component

OpenLIT Python SDK

What happened?

Schema(json_mode=True) allows unquoted NaN, Infinity, and -Infinity, including inside objects and arrays. A postflight pipeline consequently marks these invalid JSON outputs as allowed. The schema-number mode has the same parsing behavior.

Steps to reproduce

With the Python SDK from main at 1ed8bb7 (Python 3.13.7):

from openlit.guard.schema import Schema
from openlit.guard._pipeline import Pipeline
result = Pipeline(guards=[Schema(json_mode=True)]).evaluate(
    '{"score": NaN}', phase="postflight"
)
print(result.action)  # allow

Expected behavior

Configured deny/warn action with invalid_json, matching other invalid JSON syntax. Quoted strings such as "NaN" should still be allowed.

Cause and scope

Python's json.loads accepts these non-standard constants by default. Rejecting them through parse_constant keeps JSON parsing local to the Schema guard, without changing unrelated JSON consumers or adding a dependency.

Discovered through code inspection, then reproduced offline: 12 regression cases fail on current main and 6 valid-JSON controls pass. This is not a production incident report. Searched existing NaN/Infinity/parse_constant and Schema guard PRs. #1696 addresses Python booleans matching integer/number schemas, a separate type-checking issue.

Prepared with Codex assistance; reproduction executed locally.

Environment

OpenLIT Python SDK 1.45.0, source main at 1ed8bb7; Python 3.13.7 on macOS.

Pre-submission checklist

  • I searched existing issues and did not find a duplicate.

Are you willing to submit PR?

Yes, I am willing to submit a PR.

Activity

  1. changed the title [-]Schema JSON guard accepts non-JSON NaN and Infinity constants[/-] [+]Bug: Schema JSON guard accepts non-JSON NaN and Infinity constants[/+] on Oct 28, 2026
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