guidance-ai / guidance

A guidance language for controlling large language models.
MIT License
19.14k stars 1.04k forks source link

[BUG] JSON: non-required properties that occur out-of-order are validated against `additionalProperties` #1039

Closed hudson-ai closed 1 month ago

hudson-ai commented 1 month ago

Non-required properties that occur out-of-order are validated against additionalProperties, potentially leading to invalid objects.

schema = {
    "type": "object",
    "properties": {"a": {"const": "foo"}, "b": {"const": "bar"}},
    "required": ["b"],
}
test_string = '{"b": "bar", "a": "BAD"}'
grammar = gen_json(schema=schema)
assert grammar.match(test_string) is None  # FAILS
hudson-ai commented 1 month ago

Fixed by #1043