> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> Install jev-curate and filter text or dataset files from Python using PyJevCurator.

Install `jev-curate` with pip:

```bash theme={null}
pip install jev-curate==0.3.0
```

The Python package exposes `PyJevCurator`, a synchronous wrapper around the Rust `CurateFilter` pipeline and a single-threaded Tokio runtime.

## Initialize `PyJevCurator`

Pass your TypeSafe API key and a preset name (or path to a `.yaml`/`.json` rubric file). You can optionally override the model or API endpoint.

```python theme={null}
import os
from jev_curate import PyJevCurator

curator = PyJevCurator(
    api_key=os.environ["TYPESAFE_API_KEY"],
    preset="reasoning-math",
    model=None,      # defaults to jev-latest
    endpoint=None,   # defaults to https://api.typesafe.ai/v1/systemone
)
```

If `preset` does not match a built-in preset or a valid rubric file, `PyJevCurator` raises `ValueError`. If the underlying Tokio runtime fails to initialize, it raises `RuntimeError`.

## Filter a single string with `filter_text`

`filter_text(text)` runs host-side sanity checks, secret scanning, and the Jev API evaluation for one string, returning a `CurateVerdict` `dict`.

```python theme={null}
result = curator.filter_text("Step 1: Let x = 2. Therefore x + 3 = 5.")
print(result)
```

`filter_text` returns a `CurateVerdict` `dict` with four keys:

| Key | Type | Meaning |
| - | - | - |
| `passed` | `bool` | `True` when all rubric gates pass |
| `rejection_reasons` | `list[str]` | Reasons the record failed, empty when `passed` is `True` |
| `scores` | `dict[str, float]` | Score values returned for `score` questions |
| `nouls` | `dict[str, float]` | True-class probabilities returned for `noul` questions |

`filter_text` raises `RuntimeError` only on runtime/fatal errors. On row-level evaluation errors (host sanity failure, `secret_scan` match, missing answers/confidence, or Jev evaluation/API failure), `filter_text` returns a `CurateVerdict` `dict` with `passed=False` and the reason recorded in `rejection_reasons`.

## Filter a dataset file with `filter_file`

`filter_file(input, out="./curated", dry_run=False)` uses bounded streaming to read a `.jsonl` or `.parquet` file incrementally without accumulating output in memory, evaluates each row, and writes `clean.jsonl`, `rejected.jsonl`, and `errors.jsonl` to `out`.

```python theme={null}
summary = curator.filter_file(
    input="train.jsonl",
    out="./curated",
    dry_run=False,
)
print(summary)
```

Set `dry_run=True` to run host-side `secret_scan` and `pre_filter_sanity` checks locally with zero network calls.

`filter_file` returns a `dict` with row counts:

| Key | Type | Meaning |
| - | - | - |
| `passed` | `int` | Rows written to `clean.jsonl` |
| `rejected` | `int` | Rows rejected by sanity checks, secret scan, or rubric gates (`rejected.jsonl`) |
| `errors` | `int` | Rows where Jev evaluation failed (`errors.jsonl`) |
| `total` | `int` | Total rows read from `input` |

## Error handling

* Invalid `preset` values raise `ValueError` during `PyJevCurator(...)` initialization.
* `filter_text` raises `RuntimeError` only on runtime/fatal errors; row-level evaluation errors (including Jev API/transport failures) return a `CurateVerdict` `dict` with `passed=False` and details in `rejection_reasons`.
* `filter_file` raises `RuntimeError` on fatal I/O, dataset parsing, or runtime errors; per-row Jev evaluation failures are caught, counted under `errors`, and written to `errors.jsonl` rather than aborting the batch.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.