Skip to main content

beacon

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.1.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.1.0
File Size Uploaded Provenance
llm_beacon-0.1.0.tar.gz 723.6 kB With provenance Details

Built distributions (wheels)

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

Total release size: 7.4 MB

Release files / llm_beacon-0.1.0.tar.gz

Download URL llm_beacon-0.1.0.tar.gz
Size 723.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a18fe1c1247d0a94a1cec479a16c3dd23c9eea487049794b6de31e56f54bda65
BLAKE2b-256 checksum
How to use checksums
69ab8bda9e5f3b1dda00089f8214a5ad422586241f941d38cbdd2eb40081c24a
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 Oct 26, 2026.

Transparency log

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

Download URL llm_beacon-0.1.0-cp310-abi3-win_amd64.whl
Size 1.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9f7c5931eb75524ab7935072d7da9e97d778309e0d40250c81573c7c1d0d15af
BLAKE2b-256 checksum
How to use checksums
ccc821a5dc1a6cb839abedba5aa0b5e4001cb65f142301d22369649e95402d16
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 Oct 26, 2026.

Transparency log

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

Download URL llm_beacon-0.1.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
7014340e4ec6a678e4d14a537d6d56bfc076079f4bc46b2bd01d83e282aaee01
BLAKE2b-256 checksum
How to use checksums
c39256f28a8046409395b01028921fb270a649fe065994b12793278e9cfa47cc
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 Oct 26, 2026.

Transparency log

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

Download URL llm_beacon-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
0e69e98e27f1472e5faec5b94aefcd83196f6004a9e229f2f47cd40ad69b63eb
BLAKE2b-256 checksum
How to use checksums
9d021a7d1e91fae9995ae313c9be642ec52a95577cbe26de816a94d447eef1f7
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 Oct 26, 2026.

Transparency log

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

Download URL llm_beacon-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
fbde017a92a6662ba6432edcd994a3dee8fc29a0d764e1948ea35e229880e166
BLAKE2b-256 checksum
How to use checksums
5247463baafd04805df427f6e9f04520aaf94dbbd259e83390a30d56f9b84a6b
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 Oct 26, 2026.

Transparency log

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

Download URL llm_beacon-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
dbbf6373b2e0b603fc982fa634d1535be932c3c3afd5fb146958fe09772bfef8
BLAKE2b-256 checksum
How to use checksums
b6eb790047e4a14c3a47f0282f71cd119423415aa749b738afc06e6e1ab4dc33
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 Oct 26, 2026.

Transparency log

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

Download URL llm_beacon-0.1.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
81ae8652ebb3e40a1e4cb64e320a760d8c55d86a6b5080d5c908c59676b9860e
BLAKE2b-256 checksum
How to use checksums
cb7ecc69ea7a615feb0d23f6775e2c3083d8b0276946a221d5896dce187b072d
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 Oct 26, 2026.

Transparency log

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

Full provenance

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

Select from 7 files

Attestation for llm_beacon-0.1.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 Oct 26, 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.1.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