json: better support for "type" unions (e.g. nullable arrays w/ typed items)#7863
json: better support for "type" unions (e.g. nullable arrays w/ typed items)#7863ochafik merged 8 commits intoggml-org:masterfrom
json: better support for "type" unions (e.g. nullable arrays w/ typed items)#7863Conversation
…"], "items": {"type": "string"}}`)
|
Updating the integration tests with pass/fail cases for this one would help me understand better what's going on with this. |
I think we need #7790 for that ;-) In the meantime added an example to the PR's description, sorry it was a bit cryptic :-D |
json: better support for "type" unions (e.g. nullable arrays w/ typed items)
haha, thanks. :) Noted -- I've been a bit slow on that one. It's finally updated and I think it's ready for review / merge. |
|
Looks like one of the tests is failing:
|
Fixed, thanks! |
HanClinto
left a comment
There was a problem hiding this comment.
Super, super clean.
To test I reverted the change to json-schema-to-grammar.cpp and the integration test failed. Brought the changes in, and the integration test passed.
The changes are small and discrete and self-contained. Love it! ❤️❤️❤️ Enthusiastic approval -- very well done!!
…ed items) (ggml-org#7863) * json: better suport for "type" arrays (e.g. `{"type": ["array", "null"], "items": {"type": "string"}}`) * json: add test for type: [array, null] fix * update tests
Adds support for the following nullable syntax I've seen in the wild (also checked properly by https://www.jsonschemavalidator.net/):
{ "type": ["array", "null"], "items": { "type": "string" } }Before this PR, the grammar above was treated like
{"anyOf": [{"type": "array"}, {"type": "null"}]}(meaning it would accept to generate[123]).With this PR, it ensures the array is typed, e.g.
["123"]is possible but not[123]