dottxt-ai / outlines

Structured Text Generation
https://dottxt-ai.github.io/outlines/
Apache License 2.0
9.13k stars 465 forks source link

Implement JSON schema field constraints #215

Open rlouf opened 1 year ago

rlouf commented 1 year ago

We can specify constraints for the different fields in the JSON schema specification. Only maxLength for strings is currently implemented. Remaining:

Strings

and the default formats that can be specified via the format keyword:

Numeric types

Arrays

Tuples

See https://json-schema.org/understanding-json-schema/reference/array#tupleValidation

Required fields

We should handle optional fields as well, i.e. those not specified in the required field of the schema.

brandonwillard commented 1 year ago

Here are some examples of integer range constraints expressed as regular expressions: https://stackoverflow.com/a/34680927/3006474, https://3widgets.com/

CarloNicolini commented 7 months ago

What is the status of this? Are length of tuples/lists also implemented?

fire commented 7 months ago

To be honest I switched to ggml’s ebnf for grammar constraints.

brandonwillard commented 7 months ago

To be honest I switched to ggml’s ebnf for grammar constraints.

How does an EBNF-specified grammar provide these constraints?

Rassibassi commented 5 months ago

While playing around trying to validate meta schemas, I ran into $recursiveRef or $dynamicRef, any thoughts on implementation of recursive schemas? I'd like to give it a try

$recursiveRef found in: https://json-schema.org/draft/2019-09/schema https://json-schema.org/draft/2019-09/meta/core

$dynamicRef found in: https://json-schema.org/draft/2020-12/schema https://json-schema.org/draft/2020-12/meta/core

brandonwillard commented 5 months ago

While playing around trying to validate meta schemas, I ran into $recursiveRef or $dynamicRef, any thoughts on implementation of recursive schemas? I'd like to give it a try

Regarding recursion, there's an existing issue for that (albeit framed via the Pydantic interface): https://github.com/outlines-dev/outlines/issues/330. Feel free to continue the discussion there.