-
Notifications
You must be signed in to change notification settings - Fork 304
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
[feat] Add json constraint decoding to core-schema-impl/0.5.0 branch. #835
[feat] Add json constraint decoding to core-schema-impl/0.5.0 branch. #835
Conversation
…gs work for pipelines.
…, but not perfect.
…m the guard to a dedicated file for formatters.
…gs work for pipelines.
…m the guard to a dedicated file for formatters.
…hub.com:guardrails-ai/guardrails into jc/feature-add-json-constraint-core-schema-impl
…jc/feature-add-json-constraint-core-schema-impl
@@ -496,6 +500,14 @@ def from_pydantic( | |||
guard._exec_opts = exec_opts | |||
guard._output_type = schema.output_type | |||
guard._base_model = output_class | |||
if isinstance(output_formatter, str): | |||
if isinstance(output_class, list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do support root level lists for other flows. Is this restriction because of a limitation with JSONFormer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, let's make the error message more specific then to explicitly state that output_formatter="jsonformer" can't be used with root-level lists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw root-level lists are apparently an anti-pattern from an OpenAI function calling perspective - they only support top-level object for structured data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out they're valid JSON, though! I did not know that. I've edited the message to say the following:
Root-level arrays are not supported with the jsonformer argument, but can be used with other json generation methods. Omit the output_formatter argument to use the other methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw root-level lists are apparently an anti-pattern from an OpenAI function calling perspective - they only support top-level object for structured data
@zsimjee
Is this a new limitation with tools
vs the old functions
args? We've been using function calling with top level arrays with that syntax for a while now
…hub.com:guardrails-ai/guardrails into jc/feature-add-json-constraint-core-schema-impl
…hub.com:guardrails-ai/guardrails into jc/feature-add-json-constraint-core-schema-impl
…:guardrails-ai/guardrails into jc/feature-add-json-constraint-core-schema-impl
…jc/feature-add-json-constraint-core-schema-impl
Adds the formatters module and the JSONFormatter module, which in turn uses JSONFormer to better constrain the output of huggingface based models.
Performance delta on a 2023 MacBook Pro with Apple M3 Max:
These deltas may be a result of...
Further investigation is planned. Additionally, tests currently are using gpt-2 as a sample model, but we shouldn't be doing any HF imports in the tests. When core-schema-impl is merged we will have access to the new testing harnesses, including the mock models.