Lock the tokens
that must not move.
A .lensx file declares which positions in an answer are fixed to literal text or a retrieved fact, where the facts come from, and how the result is validated. The runtime turns that into a forced-anchor decode. Locked positions are excluded from the unmasking loop, so no denoising step can overwrite them.
The suite collects 259 tests, and what it reports depends on the install. On a default clone without the optional PyTorch extra it runs 253 passed, 5 skipped, 1 deselected and nothing fails. With that extra present, at commit 01e5eed, ten more tests run and it reports 256 passed, 2 skipped, 1 failed. The one failure is test_variant_factory_set, which expects the variant registry to hold exactly the seven base variants when five width-sweep entries have since been added beside them. That is a stale assertion and not a fault in the library, and it is written here because you will meet it.
YAML in. Token-locked output out.
version: "0.1"
base:
model: "cassandra-t1.5"
locks:
- range: [0, auto]
source: locus("medical:cardiology:nitroglycerin:standard_dose")
generation:
total_length: 192lensx validate examples/medical_basic.lensx lensx run examples/medical_basic.lensx --backend cassandra-t1.5 --show-provenance
The locked content from the locus appears at exactly the positions you specified. On masked-diffusion backends that holds by construction. On an autoregressive API the runtime uses logit bias and retries, and the guarantee is best-effort. The model id cassandra-t1.5 is the repository's identifier for its Cassandra T1 family backend.
Other tools constrain the shape of an answer.
lens-xt constrains the content at specific token positions. That matters when a literal disclaimer has to appear early, or a retrieved fact has to appear unchanged inside a freely generated answer.
| Approach | What it constrains | Guarantee level |
|---|---|---|
| Prompt engineering | informal natural-language hints | none |
| OpenAI structured outputs | schema fields | type-level |
| Outlines, LMQL, Guidance | regex or grammar over the output | type-level |
| JSON Schema validation | post-hoc check | retry on failure |
| LENS-XT | token positions in the answer slot | DETERMINISTIC on masked diffusion, BEST_EFFORT on an API |
The same spec, four guarantee levels
The runtime picks the strongest available backend for your spec. Switching from a local Cassandra model to OpenAI does not mean rewriting it.
| Backend | Runs where | Guarantee |
|---|---|---|
| Local masked diffusion (Cassandra T1 family, LLaDA) | self-hosted | DETERMINISTIC |
| API-compatible (OpenAI, Anthropic) | remote API | BEST_EFFORT |
| API-native diffusion (future) | remote API | DETERMINISTIC |
| Hybrid (API plus local) | mixed | DETERMINISTIC |
Three-line drop-in. Two languages.
Python · pip install lens-xt
from lens_xt import LensX
lens = LensX("medical_basic.lensx")
print(lens.run(user_input="What's the standard dose?"))Node and TypeScript · npm install @sophiaxt/lens-xt
import { LensX } from "@sophiaxt/lens-xt";
const lens = new LensX("medical_basic.lensx");
console.log(await lens.run({ user_input: "What's the dose?" }));Or skip the SDK and run the CLI directly: lensx run examples/medical_basic.lensx
What is shipped, what is next
v0.1.0a1 is an alpha, and APIs may shift before v0.1.0. End-to-end verified against a Cassandra T1 checkpoint with anchor_preservation_rate 1.000 and the DETERMINISTIC guarantee preserved.
- YAML parser, AST and validator shipped
- Lock resolver (literal, locus, retrieval, compose) shipped
- LTMi-XT keyword retrieval (v0.1) shipped
- LTMi-XT lattice-walk retrieval (v0.2, BLAKE2b section 2.4) shipped
- Reasoning scaffold runtime (multi-stage) shipped
- Local masked-diffusion backend (Cassandra T1 family) shipped
- OpenAI backend (logit-bias and retry) shipped
- HTTP API server (FastAPI) shipped
- Python SDK (LensX class) shipped
- TypeScript SDK (@sophiaxt/lens-xt) shipped
- Anthropic backend next
- Native backend for hosted diffusion APIs (Mercury) planned
Layer two of four in the stack
lens-xt gives you constrained generation. Compose it with a Cassandra T1 model below it and the SOPHIA Harness above it for a local-first, retrieval-grounded, memory-augmented system.
Cassandra T1
1.33B masked-diffusion model, Apache 2.0. The model the runtime decodes against.
LTMi-XT v0.1
Retrieval format with hash-derived indexing. The format the locks pull from.
Anchor-token masking
The training method. 1.67× held-out advantage over random-position masking.
SOPHIA Harness
Agentic memory and retrieval over lens-xt, with persistent memory per user. Built on this runtime.