Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement JSON schema field constraints #215

Open
2 of 28 tasks
rlouf opened this issue Aug 12, 2023 · 6 comments
Open
2 of 28 tasks

Implement JSON schema field constraints #215

rlouf opened this issue Aug 12, 2023 · 6 comments
Assignees
Labels
help wanted JSON structured generation Linked to structured generation

Comments

@rlouf
Copy link
Member

rlouf commented Aug 12, 2023

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

Strings

  • minLength
  • pattern

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

  • date-time
  • time
  • date
  • duration
  • email
  • idn-email
  • hostname
  • idn-hostname
  • ipv4
  • ipv6
  • uuid
  • uri
  • uri-reference
  • iri
  • iri-reference
  • uri-template
  • regex

Numeric types

  • multipleOf
  • minimum
  • exclusiveMinimum
  • maximum
  • exclusiveMaximum

Arrays

  • minItems
  • maxItems
  • uniqueItems (may only be applicable dynamically)
  • Set length

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.

@rlouf rlouf added the structured generation Linked to structured generation label Aug 12, 2023
@rlouf rlouf self-assigned this Aug 12, 2023
@brandonwillard
Copy link
Contributor

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

@CarloNicolini
Copy link

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

@fire
Copy link

fire commented Apr 4, 2024

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

@brandonwillard
Copy link
Contributor

brandonwillard commented Apr 4, 2024

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

How does an EBNF-specified grammar provide these constraints?

@Rassibassi
Copy link

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
Copy link
Contributor

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): #330. Feel free to continue the discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted JSON structured generation Linked to structured generation
Projects
None yet
Development

No branches or pull requests

5 participants