Skip to content

Bug: Schema guard crashes on a list of types, so the default pipeline allows every output #1997

Done

Description

@shlokbam

Component

OpenLIT Python SDK

What happened?

Schema raises TypeError: unhashable type: 'list' when a schema uses a list of types, such as "type": ["string", "null"]. That is how OpenAI strict structured outputs write an optional field, and what zod-to-json-schema emits for .nullable().

Because Pipeline defaults to fail_open=True, the error is logged and the guard returns allow, so the schema check is skipped for every output, including invalid ones. With fail_open=False the call raises instead.

Steps to reproduce

On main 463a1c1 (openlit 1.45.0 from PyPI gives the same result):

from openlit.guard import Schema, Pipeline

schema = {
    "type": "object",
    "properties": {"name": {"type": "string"}, "nickname": {"type": ["string", "null"]}},
    "required": ["name", "nickname"],
}

Schema(schema=schema).evaluate('{"name": "Ada", "nickname": null}')
# TypeError: unhashable type: 'list'

Pipeline(guards=[Schema(schema=schema)]).evaluate('{"name": "Ada", "nickname": 42}', phase="postflight").action
# GuardAction.ALLOW  (nickname 42 is invalid)

Expected behavior

A value that matches any type in the list passes (null and "A" here), and one that matches none of them is denied with schema_mismatch, the same as for a single type. This is what JSON Schema specifies, and jsonschema agrees on all of these cases.

Environment

OpenLIT Python SDK 1.45.0, Python 3.12.

Additional context

_validate_json_schema passes schema["type"] straight to a dict lookup (type_map.get(schema_type)), which fails for a list. I searched existing issues and PRs (including #1691 and #1865) and didn't find this. I have a fix with tests ready and can open a PR.

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