Skip to main content

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

Integrations

  • Pydantic: Round-trip conversion and nested models.
  • msgspec: High-performance validation structs.

Advanced

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


Download files

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

Source Distribution

slimschema-0.0.0.dev5.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slimschema-0.0.0.dev5-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file slimschema-0.0.0.dev5.tar.gz.

File metadata

  • Download URL: slimschema-0.0.0.dev5.tar.gz
  • Upload date:
  • Size: 55.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slimschema-0.0.0.dev5.tar.gz
Algorithm Hash digest
SHA256 0ffb7910a5ccd0ac4dd3c9db5d94c512b7c467a0c2aedf031e56e10f414e2e42
MD5 009c325f0c5feab5494001eccce9c481
BLAKE2b-256 b529b5e8be83c6ea4d11f08d042769d527a9d0bac8d4f24add1ee5d8f7f49d16

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.0.dev5.tar.gz:

Publisher: on-release-main.yml on botassembly/slimschema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slimschema-0.0.0.dev5-py3-none-any.whl.

File metadata

File hashes

Hashes for slimschema-0.0.0.dev5-py3-none-any.whl
Algorithm Hash digest
SHA256 16c65435a4f717383fca7075c4cd3552e1925965ecee93a3f0ae991638562b3b
MD5 294440da0fe91ddec4d60148b9e3b723
BLAKE2b-256 bddfd1a4c06fc02449cad6afe59f00651917a831f83d14d473f881fa73a5a876

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.0.dev5-py3-none-any.whl:

Publisher: on-release-main.yml on botassembly/slimschema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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