Skip to content

Schema guard json_mode flag is silently ignored #1999

Open

Description

@feiiiiii5

Description

The Schema guard's docstring documents json : bool — "If True, just verify the output is parseable JSON", but the constructor parameter is actually named json_mode and is stored as self._json_mode without ever being read. evaluate() always parses JSON and always applies schema validation.

Reproduction

from openlit.guard.schema import Schema

Schema(action="deny", json=True)  # TypeError: unexpected keyword 'json'
Schema(action="deny", json_mode=True, schema={"type": "integer"}).evaluate('"hello"')
# returns schema_mismatch/DENY although the output is parseable JSON

Expected

The documented parameter name works, and when it is true a parseable JSON output passes (invalid JSON is still rejected). The default schema-validation behavior is unchanged.

Proposed fix

Align the docstring with json_mode and honor the flag in evaluate() with an early ALLOW after successful parsing.

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