Skip to main content

txtest

Unit tests for written content.

txtest evaluates a text file against criteria you define with the OpenAI Decisions API. Each test produces a PASS, FAIL, or ERROR, with a short description and its value and threshold shown in the terminal.

Installation

Requires Python 3.11 or later. Install from PyPI:

python -m pip install --upgrade txtest

The CLI is included in version 0.0.2 and later. Run txtest --help to check the installation.

Set OPENAI_API_KEY in your environment or create a .env file:

OPENAI_API_KEY=your-api-key

txtest looks for .env in the current directory and its parents. An existing environment variable takes precedence.

Quickstart

The repository includes a fictional library desk-reservation policy and two demonstration tests:

To try these examples, download their files by cloning the repository:

git clone https://github.com/ThiNepo/txtest.git
cd txtest

From the repository root, run:

txtest examples/reservation-policy.md --set policies

This evaluates the complete policy with every .txtest file in txtests/policies/, in filename order. Each test makes one request, sequentially, without automatic retries. A failed test or an API error does not stop the remaining tests. Results stay in the terminal.

For a demonstration of missing information, try the incomplete policy:

txtest examples/reservation-policy-incomplete.md --set policies

Its cancellation procedure is deliberately missing, so the cancellation test is intended to produce FAIL. Scores and probabilities are model judgments and may vary between runs; these examples do not prescribe fixed output values.

The module entry point works too:

python -m txtest examples/reservation-policy.md --set policies

Writing tests

Keep each test in txtests/<set>/<name>.txtest. Sets are resolved from the current directory, and the input is one UTF-8 text file.

A test contains YAML frontmatter followed by Jinja templates in <system> and <user> blocks. For example:

---
description: Explains how to cancel a reservation.
type: predicate
min_probability: 0.5
---
<system>
Does the policy give the reader a concrete procedure for cancelling a reservation?
</system>

<user>
{{ text }}
</user>

description is required and appears beside the result so the reader can understand what was checked. The <system> block becomes the question instructions; the rendered <user> block becomes the text evaluated by that question.

The templates have three variables:

Variable Value
text The full contents of the input file.
filename The input file's name.
path The input path provided to the command.

An undefined Jinja variable produces a test error before a request is made.

Predicate tests

Use type: predicate for a yes/no condition. The result is the model's estimated probability that the condition is true, from 0 to 1. The test passes when the probability is at least min_probability, which defaults to 0.5. Probabilities and their thresholds appear as percentages in the terminal.

Score tests

Use type: score for a rubric with exactly five levels, ordered from lowest to highest. Each entry in levels needs a unique string label and a nonempty description. See the complete policy clarity test for a concrete rubric.

The result uses a 1–5 scale: the API's zero-based score is shifted by one. Fractional scores are preserved and compared with min_score, which defaults to 4, without rounding first. A score equal to the minimum passes. Each test passes or fails independently.

score is the default type when type is omitted. Predicate tests use min_probability; score tests use min_score and levels.

The accepted frontmatter fields are description, type, min_probability, min_score, levels, and model. This implementation uses gpt-6-luna by default and accepts that same value if model is explicitly set.

Exit codes

Code Meaning
0 All tests passed.
1 At least one test failed, with no execution errors.
2 A configuration, input, API, or response error occurred.

A model refusal is an error. An empty or missing test set is also an error.

Development

Run the offline test suite with:

python -m unittest discover -s tests -v

License

Apache-2.0. See LICENSE.

Metadata

Release files for txtest 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for txtest 0.0.2
File Size Uploaded Provenance Actions
txtest-0.0.2.tar.gz 21.3 kB Without provenance Details for txtest-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for txtest 0.0.2
File Interpreter ABI Platform Actions
txtest-0.0.2-py3-none-any.whl Python 3 none any Details for txtest-0.0.2-py3-none-any.whl

Total release size: 36.4 kB

Release files / txtest-0.0.2.tar.gz

Download URL txtest-0.0.2.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9d0895b31bd64ac5463654e9a74c68e227c3112737c90b658d65ba4750e3018c
BLAKE2b-256 checksum
How to use checksums
c0d08c01362f11bb3eaa7bbb566f3b3f8db347c14db171e23ae849a863db2559
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / txtest-0.0.2-py3-none-any.whl

Download URL txtest-0.0.2-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
020adfb1b2bae42e348c0d783e7f4b344af236e0d1a3dbb778d549353fb156af
BLAKE2b-256 checksum
How to use checksums
f4bd5d10fc5c4a9dacf564c543d44094734e5cf3b498062dae2cef93b7399b57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for txtest 0.0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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