Skip to main content

beacon

PyPI version Downloads Python versions License: MIT Rust

Deterministic, tested building blocks for AI pipelines.

Every block in beacon is a pure function with the same contract: same input → same output, every time, on every machine.

Stop debugging why your pipeline gave a different result yesterday.

Documentation · Playground · PyPI · GitHub

beacon is the layer between your Python code and your LLM: prompt templating, JSON extraction, tool-call parsing, schema validation, text normalization, content hashing, PII redaction, retry classification, and snapshot testing. The blocks are written in Rust (via PyO3). They have strict contracts and stable error messages, and they never silently "fix" your data.

Install

pip install llm-beacon

The PyPI package is llm-beacon; the import name is beacon.

Python 3.10–3.14. Wheels are abi3, so one wheel per platform covers every supported Python version. Integrations are optional extras: pip install "llm-beacon[langchain]", [llamaindex], [pydantic-ai], [dspy], [openai].

Quickstart

from beacon import template, extract_json, validate_schema

# 1. Render a prompt deterministically (user input is XML-escaped by default)
prompt = template(
    "Extract the user's intent as JSON.\n<message>{message}</message>",
    message="I want to cancel my subscription",
)

# 2. Call your LLM (any client)
raw_response = llm.complete(prompt)
# e.g. 'Sure! ```json\n{"intent": "cancel", "confidence": 0.93}\n```'

# 3. Extract JSON from prose, fences, or both; malformed JSON raises
result = extract_json(raw_response)

# 4. Validate against a schema. Fails loudly, never coerces.
schema = {
    "type": "object",
    "properties": {
        "intent": {"type": "string", "enum": ["cancel", "refund", "question"]},
        "confidence": {"type": "number", "minimum": 0, "maximum": 1},
    },
    "required": ["intent", "confidence"],
}
validate_schema(result, schema)

When something is wrong, the error tells you where:

>>> extract_json('The user wants to {"intent": cancel')
MalformedOutputError: expected a JSON value, found 'c' (line 1, column 30)
>>> validate_schema({"intent": "explode", "confidence": 1.5}, schema)
SchemaValidationError: 2 schema violations:
  - /intent: "explode" is not one of ["cancel", "refund", "question"]
  - /confidence: 1.5 is greater than the maximum of 1

The blocks

Block What it does
template(source, **vars) {name} substitution, single pass, strict about missing/unused variables, XML-escapes values by default ({name!raw} to opt out)
extract_json(text) Finds the JSON in fenced or prose-wrapped output; strict RFC 8259; select=/kind= for multiple values; errors include a position
parse_tool_call(text) Hermes <tool_call>, Mistral [TOOL_CALLS], Llama <|python_tag|>, [TOOL_CALL], XML <invoke>, OpenAI/Anthropic JSON, name(k=v)
validate_schema(value, schema) JSON Schema (incl. $ref, anyOf, Pydantic output). All violations come back in a fixed order with stable messages
normalize(text) NFKC, whitespace collapsing, zero-width/control removal, optional accent stripping and lowercasing
hash_content(value) BLAKE3 over a type-tagged canonical encoding; dict key order never matters
redact(text) / detect_pii(text) Emails, phones, SSNs, Luhn-checked cards, API keys, JWTs, private keys, IPs, plus your own patterns and terms
retry.classify(exc) Retry or fail, with a reason and a backoff delay. Jitter is deterministic, so the same failures give the same delays

Full reference: docs/blocks_reference.md.

Pipelines

from beacon import Block, Pipeline, extract_json, template

class ExtractIntent(Block):
    def __init__(self, llm):
        self.llm = llm

    def run(self, message: str) -> dict:
        prompt = template("Extract the intent from: <m>{message}</m>", message=message)
        return extract_json(self.llm(prompt), schema=INTENT_SCHEMA)

pipeline = Pipeline([ExtractIntent(llm), route_intent, format_reply])
pipeline.run("I want to cancel")
pipeline.run_traced("I want to cancel").trace()  # content hashes for each step

Snapshot testing

Most LLM apps have no tests because the model's output isn't deterministic. Everything around the model is, though. Record a model response once, then snapshot what your code does with it:

from beacon import extract_json
from beacon.snapshots import assert_snapshot

def test_cancel_intent():
    raw = open("fixtures/cancel.txt").read()       # recorded LLM response
    assert_snapshot("intents/cancel", extract_json(raw), input=raw, schema=INTENT_SCHEMA)

The first run writes snapshots/intents/cancel.yaml. Every later run compares against it byte for byte and shows a diff if anything changed. CI (where CI is set) fails on missing snapshots. When a change is intended:

python -m beacon.snapshots update

There's also a pytest snapshot fixture. See docs/snapshot_testing.md.

Integrations

Framework API
OpenAI SDK validated_completion, avalidated_completion, validated_tool_call
LangChain BeaconPromptTemplate, BeaconJsonOutputParser, BeaconCallbackHandler
LlamaIndex BeaconOutputParser
Pydantic AI BeaconValidator (agent.output_validator(BeaconValidator(Model)))
DSPy BeaconJSONAdapter, BeaconValidateSchema

See docs/integrations.md.

Determinism guarantees

Pure functions, stable across runs, machines, and minor versions. Error messages are part of the contract. All configuration is explicit, with no environment variables or global flags. The full contract is in docs/determinism_guarantees.md.

Development

git clone https://github.com/IND-Anshuman/beacon.git && cd beacon
python -m venv .venv && . .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install maturin pytest pyyaml
maturin develop
pytest                                   # Python tests + snapshot tests
cargo test --no-default-features         # Rust core tests (no Python needed)
cargo clippy --all-targets -- -D warnings
python benches/determinism_overhead.py   # per-call overhead

License

MIT

Metadata

Release files for llm-beacon 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-beacon 0.3.0
File Size Uploaded Provenance Actions
llm_beacon-0.3.0.tar.gz 113.9 kB With provenance Details for llm_beacon-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for llm-beacon 0.3.0
File Actions
llm_beacon-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for llm_beacon-0.3.0-cp310-abi3-win_amd64.whl
llm_beacon-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for llm_beacon-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
llm_beacon-0.3.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for llm_beacon-0.3.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
llm_beacon-0.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for llm_beacon-0.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
llm_beacon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for llm_beacon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
llm_beacon-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for llm_beacon-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 7.2 MB

Release files / llm_beacon-0.3.0.tar.gz

Download URL llm_beacon-0.3.0.tar.gz
Size 113.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a374410ec52e16268648758b29a2fb50f620b71eb0d568c8655aa1652aa83728
BLAKE2b-256 checksum
How to use checksums
16c0ed72da6510324dbb9b48313c472eaf8a8daba3bd0cbb6672d3309e9170aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / llm_beacon-0.3.0-cp310-abi3-win_amd64.whl

Download URL llm_beacon-0.3.0-cp310-abi3-win_amd64.whl
Size 1.1 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
82a9596c583b661856ee531b37c77a6fb0faad2e2e61804d9d0fca1ae3533a48
BLAKE2b-256 checksum
How to use checksums
e448b35f68edb3cf82c02e15bc2f94a9e82c40f875a2f24f6f4f5bf94e01b14f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / llm_beacon-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL llm_beacon-0.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
467d31fabba8c97b698988f1852063619662b5e4786d79ae8c7bcf9bebf15b8b
BLAKE2b-256 checksum
How to use checksums
1a0d7ca695515f309187cc6e1aa5a6203b268e3fbcfe12968522e84c8064e6ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / llm_beacon-0.3.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL llm_beacon-0.3.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
dd53b68bbbc22f95857d39f5ec0667239babeb5e0913fd38a4fd06e90af5c9ef
BLAKE2b-256 checksum
How to use checksums
4ec448dd9ccd14e7ff73206e2cdff0469283ca86cf66e5d1a22715b53cb473a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / llm_beacon-0.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL llm_beacon-0.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
1cc91ee65869fa1d76ea9522ca208afd70378b709a9a0d88a6ebfc8f13391d73
BLAKE2b-256 checksum
How to use checksums
6b67695018406d67994e07b28a196a7788ce7fa8899b50de59883df98fa90d13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / llm_beacon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL llm_beacon-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a84b85a56665c93ca5250cc874af0dba2073661652c9daaf8f94ee30c5d90f2f
BLAKE2b-256 checksum
How to use checksums
9ddfc6477af815d2bd5833b98e0166c9be068b0952e6255ce75e1a27d026b6b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / llm_beacon-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL llm_beacon-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2a0007a68cfd2b2c44fee813646513ba2b062686623f06fd3892550b0aeaf664
BLAKE2b-256 checksum
How to use checksums
69141bd722ffe2b9631fe7fede39c9c6e4a137cbbc988ae6c1d09db7e38b37ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for llm-beacon 0.3.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.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for llm_beacon-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

7 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page