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

Modify JSON schema $ref resolution strategy to support resolving values internal to the schema #312

Merged

Conversation

mattkindy
Copy link
Contributor

Overview

Previously, only $ref that were directed to #/$defs could be resolved via the use of a pre-loaded definitions variable. This PR modifies the behaviour of $ref resolutions by instead using a resolver function, which is generated to scope to a particular schema or subschema.

  • This is still preloaded with #/$defs as before
  • $ref keys are split to traverse through the scoped schema. When found, they are cached for re-use to avoid re-traversing
  • In expand_json_schema, $id is an identifier of a scope change, and a new resolver linked to the schema for that scope is used for its children (e.g. for supporting bundling)
  • Recursion is supported -- note that no effort is made to identify if this recursion is valid or could lead to infinite loops

Fixes #310 for local references (i.e. doesn't attempt to address remote schemas)

@mattkindy mattkindy changed the title Modify resolution strategy to support resolving values internal to the schema Modify JSON schema $ref resolution strategy to support resolving values internal to the schema Oct 2, 2023
@mattkindy mattkindy force-pushed the kindy-support-ref-resolutions branch from f464ea7 to e332727 Compare October 2, 2023 21:52
Copy link
Contributor

@brandonwillard brandonwillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, and much appreciated, @mattkindy!

@brandonwillard brandonwillard merged commit 4ce76ff into outlines-dev:main Oct 3, 2023
5 checks passed
@brandonwillard brandonwillard added enhancement JSON structured generation Linked to structured generation labels Oct 3, 2023
@mattkindy mattkindy deleted the kindy-support-ref-resolutions branch October 3, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement JSON structured generation Linked to structured generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON schema parsing doesn't handle $ref properly
2 participants