llm-response-schema-lite-py
Tiny schema validator for structured LLM responses. Two schema formats: a one-line shape spec ({"name": "str", "age": "int"}) and the JS-sibling rule format ({"name": {"type": "str", "required": True, "enum": [...]}}). Returns a (valid, errors) result you can hand straight back to the LLM as feedback. Zero runtime dependencies.
Python port of @mukundakatta/llm-response-schema-lite.
Install
pip install llm-response-schema-lite-py
Quick start
Shape format (Python-friendly, 1-liner)
from llm_response_schema_lite import validate
schema = {"name": "str", "age": "int", "tags": "list", "email": "str?"}
validate({"name": "Ada", "age": 36, "tags": ["scientist"]}, schema)
# ValidationResult(valid=True, value={...}, errors=[])
validate({"name": "Ada", "age": "thirty-six"}, schema)
# ValidationResult(valid=False, errors=[
# {"path": "age", "message": "expected_int"},
# {"path": "tags", "message": "required"}
# ])
Suffix a type with ? to mark it optional. Supported types: str, int,
float, bool, list, dict (and JS aliases: string, number,
boolean, array, object).
JS-sibling rule format (full feature parity)
schema = {
"status": {"type": "str", "required": True, "enum": ["ok", "error"]},
"code": {"type": "int", "required": False},
}
validate({"status": "ok", "code": 200}, schema) # valid
validate({"status": "weird"}, schema) # not_in_enum
validate({}, schema) # required
Parse JSON + validate in one shot
from llm_response_schema_lite import parse_and_validate
result = parse_and_validate('{"name": "Ada"}', {"name": "str"})
result.valid # True
result.value # {"name": "Ada"}
If JSON parsing fails, you get back ValidationResult(valid=False, value=None, errors=[{"path": "$", "message": "invalid_json"}]).
API
validate(value, schema) -> ValidationResultparse_and_validate(json_str, schema) -> ValidationResultvalidate_response(value, schema)-- JS-parity alias ofvalidate.
ValidationResult is a dataclass with valid: bool, value: Any | None, errors: list[dict].
License
MIT
Metadata
Release files for llm-response-schema-lite-py 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llm_response_schema_lite_py-0.1.0.tar.gz | 5.2 kB | Without provenance | Details for llm_response_schema_lite_py-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_response_schema_lite_py-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for llm_response_schema_lite_py-0.1.0-py3-none-any.whl |
Total release size: 10.7 kB
Release files / llm_response_schema_lite_py-0.1.0.tar.gz
| Download URL | llm_response_schema_lite_py-0.1.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a21b57cab51ff9fd5a4546cdb66d04840a6b4846cda6dfe13af907bf8e2dbf69
|
|
BLAKE2b-256 checksum How to use checksums |
b2d8a3a934b6f136b3d3f4da4e0ddc8dcbca4411e4dc06db8275f472e46e91dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / llm_response_schema_lite_py-0.1.0-py3-none-any.whl
| Download URL | llm_response_schema_lite_py-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3efd54210a7c6c16015eb5f2b293b579f82bba79c7c3ec719989332ef7b25e52
|
|
BLAKE2b-256 checksum How to use checksums |
d5d1ca45162c62128b70b191f6419db963ac4faf400967b08645da5143f008af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for llm-response-schema-lite-py 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.