Every value is origin, at a boundary, or contents. The runtime enforces which.
Project description
Origin
Every value is origin, at a boundary, or contents. The runtime enforces which.
When your model isn't sure about something — low confidence, out of its training domain, potentially hallucinating — that uncertainty usually lives in a float field that someone might forget to check. Origin changes that.
But here's what makes it different from try/except: when something goes wrong, Origin doesn't throw away what the model computed. It keeps it. And when the system hits its absolute boundary — no output at all — that's a distinct sort, not just None.
from origin_lang import Value, boundary
@boundary
class LowConfidence:
confidence: float
threshold: float
# Three sorts. The runtime enforces which.
match infer(text):
case Value.Contents(diagnosis):
treat(diagnosis)
case Value.Boundary(LowConfidence(confidence=c), last=diagnosis):
refer_to_specialist(diagnosis, c)
# ^^^^^^^^^
# still here
case Value.Origin(reason):
escalate(reason)
That's the difference between a system that says "I don't know" and a system that says "here's my full reasoning up to the point where I ran out of certainty."
| What survives a boundary | try/except |
Origin |
|---|---|---|
| That something went wrong | yes | yes |
| Which boundary was crossed | sometimes | yes |
| What the computation last knew | opt-in | guaranteed |
| Absolute boundary vs edge | no | yes |
Zero dependencies. Pure Python. Works with any model framework.
For compile-time enforcement, see the Rust crate.
Install
pip install origin-lang
API
from origin_lang import Value, boundary
from origin_lang.value import match, BoundaryError
# Define a boundary kind
@boundary
class MyBoundary:
reason: str
# Create values — three sorts
v = Value.contents(result) # safe territory
v = Value.boundary(MyBoundary(reason="uncertain"), last=partial) # crossed edge, last value preserved
v = Value.origin(MyBoundary(reason="system failure")) # absolute boundary, no value
# Inspect
v.is_contents # True/False
v.is_boundary # True/False
v.is_origin # True/False
v.unwrap() # returns value or raises BoundaryError
v.or_default(x) # returns value or fallback
v.or_else(on_boundary, on_origin) # handle each sort distinctly
v.map(fn) # transform contents and boundary's last; origin passes through
# or_else — handle each sort without a full match
result = v.or_else(
lambda reason, last: f"uncertain ({reason.confidence:.0%}): {last}",
lambda reason: f"failed: {reason}",
)
# Pattern match (Python 3.10+)
m = match(v)
match m:
case Value.Contents(value):
use(value)
case Value.Boundary(reason, last=residual):
handle(reason, residual)
case Value.Origin(reason):
escalate(reason)
Where This Came From
Origin is formally verified in the two-sorted arithmetic project — 508 Lean 4 theorems proving that three sorts are necessary and sufficient. The Rust crate provides compile-time enforcement. This Python package provides runtime enforcement with the same vocabulary.
Three sorts. The last field is always preserved in Boundary. Origin carries only the reason. Contents carries the value.
Note: the Rust crate includes Chain for reasoning traces (showing every step before a boundary was hit). The Python package does not yet implement Chain — pattern matching and or_else are the primary tools for handling boundaries in Python.
Zero external dependencies. Uses only dataclasses from the standard library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file origin_lang-0.2.0.tar.gz.
File metadata
- Download URL: origin_lang-0.2.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9703ec04f5020ea31be687792d2ec5cdb1f27c0e4f9811ebf2878eec44af3e60
|
|
| MD5 |
ea2c90110dec8dbe87542e6ba421b6f4
|
|
| BLAKE2b-256 |
e179d5450166f246969791909f7fecc15f733aca4ecdf99e8931d5ac8c1d47ff
|
File details
Details for the file origin_lang-0.2.0-py3-none-any.whl.
File metadata
- Download URL: origin_lang-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce6ac239acc4f8396f74c27a9b5411243018e36350016b4074d87b6e6e04345d
|
|
| MD5 |
4a9c146274d604503f675d34b7cce7e9
|
|
| BLAKE2b-256 |
9cb2fc7a0b5d4e59a4c706278dcc3efd4c702b57c6f7f685fba4b5c7e66bcbdc
|