Token-efficient schema language for LLMs with validation and conversion
Project description
SlimSchema
The bridge between LLMs, Python types, and fast validation.
SlimSchema is a schema language optimized for LLM token efficiency (70% smaller than JSON Schema) that converts seamlessly between YAML, Pydantic, and msgspec.
Core Features
- Token Efficient: Compressed syntax (
age: 18..120) saves context window and costs. - Deep Validation: Recursive validation for nested objects and dictionaries.
- Robust Extraction: extract JSON/XML from noisy LLM markdown.
- Universal Bridge: Convert any format to any format (YAML ↔ Pydantic ↔ msgspec).
Quick Start
pip install slimschema
The Magic Example
Define a schema with nested types and defaults, extract data from an LLM response, and get a validated Python object.
from slimschema import to_data, to_pydantic
# 1. Define a compact schema (with nested defaults!)
schema = """
user:
name: str{3..50}
role: admin | user | guest = "guest"
settings:
theme: str = "dark"
notifications: bool = true
"""
# 2. Validate LLM output (even if partial)
# Input missing 'settings' -> defaults apply automatically
llm_output = '{"user": {"name": "Alice"}}'
data, error = to_data(llm_output, schema)
print(data)
# {
# "user": {
# "name": "Alice",
# "role": "guest",
# "settings": {"theme": "dark", "notifications": True}
# }
# }
# 3. Convert to Pydantic for your app
UserModel = to_pydantic(schema)
instance = UserModel(**data)
print(instance.user.settings.theme) # "dark"
Documentation
Guides
- Syntax Guide: Primitives, constraints, and inline objects.
- Validation Guide: How
to_datavalidates and reports errors. - Defaults Guide: Handling partial data with scalar and nested defaults.
- LLM Workflow: Generating prompts and robust extraction.
- Inference Guide: Bootstrapping schemas from data.
Integrations
Advanced
- JSON Patch: RFC 6902 support.
API Reference
to_data(response, schema): Extract and validate JSON.to_schema(obj): Convert Pydantic/msgspec/YAML to SlimSchema IR.to_prompt(schema): Generate token-optimized prompts.from_data(data): Infer schema from examples.to_pydantic(schema): Generate Pydantic models.to_msgspec(schema): Generate msgspec structs.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slimschema-0.0.0.dev7.tar.gz.
File metadata
- Download URL: slimschema-0.0.0.dev7.tar.gz
- Upload date:
- Size: 61.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f8a46429bdc54d5d13b89f78ab4e1f59d95c22628fb973972627aff8972cb12
|
|
| MD5 |
8e3c27e26b6e5b550095e2c4cb21b245
|
|
| BLAKE2b-256 |
3a358600dd9d6d00cef40cb165ab3d807a2fdfb02a40e8da5179a4adbaf1ec8f
|
Provenance
The following attestation bundles were made for slimschema-0.0.0.dev7.tar.gz:
Publisher:
on-release-main.yml on botassembly/slimschema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slimschema-0.0.0.dev7.tar.gz -
Subject digest:
5f8a46429bdc54d5d13b89f78ab4e1f59d95c22628fb973972627aff8972cb12 - Sigstore transparency entry: 711099305
- Sigstore integration time:
-
Permalink:
botassembly/slimschema@1bae26c27c3604afb087ee21fc116e38581e7e65 -
Branch / Tag:
refs/tags/v0.0.0dev7 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@1bae26c27c3604afb087ee21fc116e38581e7e65 -
Trigger Event:
release
-
Statement type:
File details
Details for the file slimschema-0.0.0.dev7-py3-none-any.whl.
File metadata
- Download URL: slimschema-0.0.0.dev7-py3-none-any.whl
- Upload date:
- Size: 41.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c308291f949f024562add319998622f799541042a211d7ee70cb3d9bb6574e4
|
|
| MD5 |
413faee27fec3988f18623d929dc9cca
|
|
| BLAKE2b-256 |
16f0309144a90228d69e740ff1cca7e5dd46335d6a0d9457485cc444d8340876
|
Provenance
The following attestation bundles were made for slimschema-0.0.0.dev7-py3-none-any.whl:
Publisher:
on-release-main.yml on botassembly/slimschema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slimschema-0.0.0.dev7-py3-none-any.whl -
Subject digest:
9c308291f949f024562add319998622f799541042a211d7ee70cb3d9bb6574e4 - Sigstore transparency entry: 711099362
- Sigstore integration time:
-
Permalink:
botassembly/slimschema@1bae26c27c3604afb087ee21fc116e38581e7e65 -
Branch / Tag:
refs/tags/v0.0.0dev7 - Owner: https://github.com/botassembly
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@1bae26c27c3604afb087ee21fc116e38581e7e65 -
Trigger Event:
release
-
Statement type: