WIP: Fix Various JSON-Schema Generation Bugs #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
The repetition problem of language models combined with patterns allowing for infinite-length fields results in broken JSON Schema outputs.
This was addressed previously for infinite whitespaces issues by setting a safe whitespace pattern as the default. In this PR, the safety of whitespaces is extended to Integer and String patterns.
Behavior
json_schema.to_regex
now includes an kwargsafe_subset=True
.safe_subset=False
r"[\n\t ]*"
safe_subset=True
(default)r"[ ]?"
Fixes
Safe Integer
Safe String
non_strict
mode)prompts
Using Chat Templates inSequenceGeneratorAdapter
dottxt-ai/outlines#987Further Work
Important: Low quality outputs are often caused by not applying a chat template. All examples should include chat templates, or user response quality will suffer. Format
prompts
Using Chat Templates inSequenceGeneratorAdapter
dottxt-ai/outlines#987Make code more failsafe: Add a non_strict mode to deal with JSONDecodeError errors dottxt-ai/outlines#985
number
has nosafe_subset
implementation. Its' likely the only unsafe primitive remaining without one. There aren't any open issues for an error caused by number, however.