Skip to main content

Token-efficient schema language for LLMs with fast Zig backend

Project description

SlimSchema

SlimSchema is a schema toolkit with two entry points:

  • SlimSchema YAML (Zig-first): a compact, YAML-shaped schema language for token-efficient prompts and interop.
  • Spec API (typed-first): derive JSON Schema + validation from language types:
    • Python: @spec decorator on dataclasses
    • Zig: Spec(T) for comptime schema generation

Both surfaces are intended to share the same core concepts (constraints, formats, defaults, error paths) while targeting different workflows.

Python Quickstart (@spec)

uv pip install slimschema
pip install slimschema
from typing import Annotated

from slimschema import Alias, Len, Range, spec


@spec
class User:
    user_name: Annotated[str, Alias("userName"), Len(1, 50)]
    age: Annotated[int, Range(0, 120)]

# Load from JSON (mirrors json.loads)
user = User.loads('{"userName": "Alice", "age": 30}')
assert user.user_name == "Alice"
assert user.age == 30

# Dump to JSON (mirrors json.dumps)
json_str = user.dumps()

# Load from dict (mirrors json.load)
user2 = User.load({"userName": "Bob", "age": 25})

# Dump to dict (mirrors dataclasses.asdict)
data = user2.dump()
assert data == {"userName": "Bob", "age": 25}

Zig Quickstart (YAML + Spec(T))

YAML DSL:

const slimschema = @import("slimschema");

const yaml =
    \\name: str{1..50}
    \\age: 0..120
;

Typed spec:

const slimschema = @import("slimschema");

const User = struct { name: []const u8, age: i64 };
pub const user_json_schema = slimschema.jsonSchemaFromType(User);

SlimSchema YAML (Full Spec)

# Primitives
name: str                    # string
age: int                     # integer
score: float                 # floating point number
active: bool                 # boolean (true/false)
meta: obj                    # any object/dict
anything: any                # any JSON value

# Format types (validated)
email: email                 # email address
website: url                 # URL (http/https)
birthday: date               # date (YYYY-MM-DD)
timestamp: datetime          # ISO datetime
user_id: uuid                # UUID format

# Constraints
username: str{3..50}         # string length 3-50 chars
age_range: 18..120           # integer range 18-120
code: /^[A-Z]{3}$/           # regex pattern match

# Collections
tags: list[str]              # array of strings
unique_ids: set[int]         # array of unique integers
coords: tuple[float, float]  # fixed-length tuple [x, y]
scores: dict[str, int]       # object with string keys, int values

# Enums and Unions
status: active | pending     # enum: one of these values
value: str | int             # union: string OR integer

# Optional vs Nullable
?nickname: str               # ? prefix: field can be omitted
rating: float?               # ? suffix: value can be null
?notes: str?                 # both: omittable AND nullable

# Hidden fields (excluded from LLM prompts)
_internal_id: str            # _ prefix: hidden field
_?debug_info: str            # hidden + optional

# Default values
count: int = 0               # literal default
role: str = "user"           # quoted string default
items: list = []             # empty list default
config: dict = {}            # empty dict default

# Default generators (auto-generated if omitted)
id: uuid = uuid              # UUID v4
id_v7: uuid = uuid7          # UUID v7 (time-ordered)
id_ulid: str = ulid          # ULID (sortable, 26 chars)
id_xid: str = xid            # XID (compact, 20 chars)
id_nano: str = nanoid        # NanoID (URL-safe, 21 chars)
created: datetime = now      # current UTC datetime
day: date = today            # current UTC date
ts: int = epoch              # unix timestamp (seconds)

# Nested objects (indentation-based)
user:                        # parent field with nested structure
  name: str                  # child field
  age: int
  address:                   # deeply nested
    street: str
    city: str
    zip: str{5..10}

# Inline objects (single-line syntax)
point: {x: float, y: float}  # compact object definition

# YAML list syntax (array of objects)
issues:                      # parent field becomes array
  - file: str                # first field on dash line
    line: int                # additional fields indented
    severity: str
    message: str

# Complex example: API response schema
response:
  success: bool
  data:
    total: int
    page: 1..100
    items:                   # nested list
      - id: uuid
        name: str{1..100}
        ?tags: list[str]
        created: datetime
  ?error: str

Documentation

  • docs/README.md (start here)
  • docs/WHY.md (architecture decisions: Python/Zig split, when to use each API)
  • docs/python/README.md (Python @spec)
  • docs/zig/README.md (Zig YAML + Spec(T))
  • docs/dev-guide.md (development workflow)
  • DOCS_INVENTORY.md (doc gaps + migration plan)

Development

make build
make test
make coverage

Zig tests:

cd zig && zig build test

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.1.dev9.tar.gz (39.1 kB view details)

Uploaded Source

Built Distributions

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

slimschema-0.0.1.dev9-py3-none-win_amd64.whl (23.0 kB view details)

Uploaded Python 3Windows x86-64

slimschema-0.0.1.dev9-py3-none-manylinux_2_17_x86_64.whl (1.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

slimschema-0.0.1.dev9-py3-none-macosx_11_0_arm64.whl (681.6 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file slimschema-0.0.1.dev9.tar.gz.

File metadata

  • Download URL: slimschema-0.0.1.dev9.tar.gz
  • Upload date:
  • Size: 39.1 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.1.dev9.tar.gz
Algorithm Hash digest
SHA256 ed420935bb04d0dd2ae32a498770512673b1b109d56dd511506385839077e50d
MD5 d89098555ae8ab5078750bffcfc7d1fe
BLAKE2b-256 c830d8651cd42fd8a95ee04a58488cd0e4dcaa5a245cc835397cd65526f17418

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev9.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.1.dev9-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev9-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 0cfbd71eb90104d99c66c8cadd10daae7ad6bcb633bbbc851e1f102fc306b4b7
MD5 1194670d9187c042b21f18350d4e2d24
BLAKE2b-256 7c26180626f955552824f202f07a77b0f9c7abf770b6b27ed46c3fecc6824ed5

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev9-py3-none-win_amd64.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.

File details

Details for the file slimschema-0.0.1.dev9-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev9-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8f94f7390b3d595c1c1670695b2e5b028ee383d4917b446b5f1a8c719a77f729
MD5 b68a275f97140674466208027b3b1f87
BLAKE2b-256 f0c7bd95cb1d583ae320a9f087a3859240370210f9271170ec58c3f3de4b886a

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev9-py3-none-manylinux_2_17_x86_64.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.

File details

Details for the file slimschema-0.0.1.dev9-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for slimschema-0.0.1.dev9-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 23ffc5b0cc63f85569a5228a64b622381862e220f75235467dbc81816dde24dd
MD5 f0f60e8c3267ff9e03a1d8b925eb1d80
BLAKE2b-256 dc1f74f0e406a5060a56a75c11720ba658208003bc485298e7b156eecd11c1fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for slimschema-0.0.1.dev9-py3-none-macosx_11_0_arm64.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