Metadata-Version: 2.4
Name: origin-lang
Version: 0.1.1
Summary: Every value is interior or at a boundary. The runtime enforces which.
License-Expression: MIT
Project-URL: Homepage, https://github.com/knoxvilledatabase/origin
Keywords: ai,safety,boundary,inference,type-system
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# Origin

Every value is either in the interior or at a boundary. 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.

```python
from origin_lang import Value, boundary

@boundary
class LowConfidence:
    confidence: float
    threshold: float

# The value the model computed is still here
# even when confidence is too low to act on
match infer(text):
    case Value.Interior(diagnosis):
        treat(diagnosis)
    case Value.Boundary(LowConfidence(confidence=c), last=diagnosis):
        refer_to_specialist(diagnosis, c)
        #                   ^^^^^^^^^
        #                   still here
```

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** |

Zero dependencies. Pure Python. Works with any model framework.

For compile-time enforcement, see the [Rust crate](https://github.com/knoxvilledatabase/origin).

## Install

```bash
pip install origin-lang
```

## API

```python
from origin_lang import Value, boundary
from origin_lang.value import match, BoundaryError

# Define a boundary kind
@boundary
class MyBoundary:
    reason: str

# Create values
v = Value.interior(result)
v = Value.boundary(MyBoundary(reason="too uncertain"), last=partial_result)

# Inspect
v.is_interior    # True/False
v.is_boundary    # True/False
v.unwrap()       # returns value or raises BoundaryError
v.or_default(x)  # returns value or fallback
v.map(fn)        # transform both interior and last

# Pattern match (Python 3.10+)
m = match(v)
match m:
    case Value.Interior(value):
        use(value)
    case Value.Boundary(reason, last=residual):
        handle(reason, residual)
```

## Where This Came From

Origin is a proof of concept from the [two-sorted arithmetic](https://github.com/knoxvilledatabase/two-sorted-arithmetic) project. The [Rust crate](https://github.com/knoxvilledatabase/origin) provides compile-time enforcement. This Python package provides runtime enforcement with the same vocabulary.

The concept is the same. The `last` field is always preserved. The boundary is always named.
