This constrains the output of the LLM to some grammar.
However, why not use a grammar that does not have invalid sentences, and from there convert to any grammar that you want?
However, why not use a grammar that does not have invalid sentences, and from there convert to any grammar that you want?
With a 2nd pass you basically "condition" it on the text right above, hoping to get better semantic understanding.
{
"$id": "https://example.com/test.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Person",
"type": "object",
"properties": {
"hp": {
"type": "integer",
"description": "HP",
"minimum": 1,
"maximum": 15
}
}
}
is converted to this BNF-like representation: hp ::= ([1-9] | "1" [0-5]) space
hp-kv ::= "\"hp\"" space ":" space hp
root ::= "{" space (hp-kv )? "}" space
space ::= | " " | "\n"{1,2} [ \t]{0,20}