Skip to main content

A progressive JSON schema validator

Project description

JSON schema enforcer

A progressive JSON schema validator. For use with large language models, to force their output to strictly adhere to a pre-defined schema. The goal is to be able to validate whether the partial JSON output breaks the schema, in a way where you can't get yourself into a dead end - if "...ab" is valid, then there is an x for which "...abx" is valid, all the way until you got the complete output.

This is a quick experiment to show how easy it is to implement a JSON schema enforcer. I made it out of spite after OpenAI didn't enforce the schema of the returns of the function call feature, and I made it in a day, which does prove my point - OpenAI could have done this, they just didn't bother.

Note that I am not a programming language developer, not at all, therefore I fully expect this code to be very shitty.

Another note: I am not using the full JSON schema specification, but my own simplified standard similar to the one OpenAI use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_schema_enforcer-0.1.0.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

json_schema_enforcer-0.1.0-py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page