Skip to main content

Project STROT (strot-ai)

PyPI Python License

Compile-time LLM code synthesis, deterministic runtime routing.

An open-source implementation of the STROT framework (Structured Task Reasoning and Output Transformation) extended with an NLU strategy-pattern runtime: a large generative LLM scaffolds your execution paths once at compile time, and a small, fast NLU model routes every record deterministically at runtime — baked into a single standalone Python file.

┌──────────────────────── COMPILE TIME ────────────────────────┐
│ dataset sample ─▶ schema introspection (Phase 1)             │
│                ─▶ prompt scaffolding   (Phase 2)             │
│                ─▶ LLM code synthesis + self-correction loop  │
│                   (Phase 3, bounded retries on error traces) │
│                ─▶ compiled_pipeline.py  (standalone asset)   │
└──────────────────────────────────────────────────────────────┘
┌───────────────────────── RUNTIME ────────────────────────────┐
│ record ─▶ NLU router (local CPU transformer OR hosted API)   │
│        ─▶ confidence >= 0.40 ? dispatch : FallbackException  │
│        ─▶ statically compiled execution path                 │
└──────────────────────────────────────────────────────────────┘

Installation

pip install strot-ai            # core (pure stdlib)
pip install strot-ai[local]     # + torch/transformers for local NLU
pip install strot-ai[hosted]    # + openai for hosted NLU / synthesis

Quick start

from strot import StrotCompiler
from strot.compiler import openai_llm_client

tickets = [
    {"ticket_id": 101, "channel": "email", "body": "I was double charged"},
    {"ticket_id": 102, "channel": "chat",  "body": "App crashes on export"},
]

compiler = StrotCompiler(
    nlu_model="SupersonicLabs/Julia-1",     # default: local, CPU, Apache-2.0
    llm_client=openai_llm_client("gpt-4o"), # the compile-time synthesizer
)

asset = compiler.compile(
    sample=tickets,
    goal="Triage incoming support tickets into the correct workflow.",
    action_registry={
        "billing_dispute":  "Refunds, invoice corrections, double charges",
        "technical_defect": "Crashes, bugs, broken behavior",
    },
)
asset.save("compiled_pipeline.py")          # completely self-contained

Then, anywhere in production (no strot dependency required):

from compiled_pipeline import CompiledPipeline, FallbackException

pipeline = CompiledPipeline()
try:
    outcome = pipeline.process({"ticket_id": 7, "body": "charged twice"})
    print(outcome)  # {"action": "billing_dispute", "confidence": 0.93, "result": {...}}
except FallbackException as exc:
    quarantine(exc)  # confidence < 0.40 — never execute a random path

See examples/end_to_end.py for the full walkthrough (it also runs offline with a stub synthesizer).

The two runtime architectures

The nlu_model string selects which runtime gets compiled into the asset:

Implementation Alpha — local encoder (default SupersonicLabs/Julia-1). Loads via transformers, forced onto torch.device("cpu"). Options are rendered in the Julia-1 token format (Context: ...\nQuestion: ...\nOptions: ...\nAnswer:) and scored from the logits of a single forward pass (<40 ms on CPU). If the action registry exceeds 20 keys, an Option Tree Splitter decomposes the decision into a multi-tier hierarchy, since Julia-1 accuracy degrades beyond 20 choices.

Implementation Beta — hosted API (e.g. openai/gpt-4o-mini). An ultra-lightweight block: API keys from os.environ, zero torch/transformers imports (tiny container footprint), and Structured Outputs (strict JSON Schema) forcing the provider to return only the integer index of the winning execution path.

Both runtimes enforce the same guard: if the calibrated confidence of the winning path is below 0.40, the asset raises FallbackException instead of executing blindly.

API surface

Symbol Role
StrotCompiler Phase 1–3 orchestration: introspect → scaffold → synthesize → assemble
CompiledAsset The standalone artifact; .save("compiled_pipeline.py")
introspect_schema Schema profiler: semantic types, cardinality, null rates, samples
create_router / Router Library-side routing with confidence enforcement
LocalEncoderStrategy / HostedApiStrategy The two runtime strategies
FallbackException Raised when max_probability < 0.40
CompilationError Synthesis failed after the self-correction retry budget

How the self-correction loop works

Following the STROT paper's feedback-driven refinement phase, the compiler validates every LLM response before accepting it — syntax (ast.parse), the output contract (one execute_<key> function per registry entry), and an import blocklist (execution paths must stay stdlib-pure). On failure, the error trace and the rejected code are appended to the original prompt and the synthesizer retries, up to max_retries attempts, after which CompilationError is raised.

Development

poetry install --extras all
poetry run pytest

License

MIT — see LICENSE.

Metadata

Release files for strot-ai 0.2.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 strot-ai 0.2.0
File Size Uploaded
strot_ai-0.2.0.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for strot-ai 0.2.0
File Interpreter ABI Platform
strot_ai-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.5 kB

Release files / strot_ai-0.2.0.tar.gz

Download URL strot_ai-0.2.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c35910b3ceabecf5784cf4a99cf8f1ac902656bd73e0355f4d6476161f995de7
BLAKE2b-256 checksum
How to use checksums
78f12d6b0393041ac564bed1f841de48a9afd9813144f12c4d6295ad4f9af617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release files / strot_ai-0.2.0-py3-none-any.whl

Download URL strot_ai-0.2.0-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e427f2682c6d516f0373338d66d3c6e9f4a31ef01b158f6c78e37e45115ea30d
BLAKE2b-256 checksum
How to use checksums
de878d0508bebcf6f6e746d7e72565f4a40d9b367eb51ed72def47561bf0cf6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 11, 2026.

Transparency log

Release history Release notifications | RSS feed

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

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