Skip to main content

choiceone

A type-safe decision layer between your Python code and an AI model.

Instead of generating prose and parsing it back, choiceone sends an unstructured state plus a closed set of typed questions and returns typed, probabilistic decisions your code can branch on directly. Answers cannot have a type error: they are always a distribution over the options you supplied.

Implements the "ChoiceOne" protocol: state in, typed probabilistic decisions out.

Install

pip install choiceone            # core, no model dependencies
pip install 'choiceone[local]'   # + local Hugging Face backend (torch, transformers)
pip install 'choiceone[server]'  # + HTTP server (fastapi, uvicorn)

Quick start

from choiceone import ChoiceOne, Choice

so = ChoiceOne()  # default local model
response = so(
    state="My running shoes arrived in the wrong size.",
    questions={
        "department": Choice(
            instructions="Which team should handle this?",
            criteria={
                "returns": "Exchanges, wrong or damaged items",
                "shipping": "Delivery status, delays, lost packages",
                "billing": "Charges, invoices, payment problems",
            },
        ),
    },
)

answer = response.answers["department"]
print(answer.choice, answer.probabilities, answer.confidence)

Primitives

Question Returns
Choice choice, probabilities, confidence
Score score, legend, probabilities, confidence
Noul noul (probability the statement is true, 0-1)

Every Choice/Score answer includes a confidence derived from how peaked the distribution is, so your code can act automatically, ask, or escalate.

Backends

The model side is a pluggable Backend. choiceone ships with these:

  • LocalBackend — a local Hugging Face causal LM (default Qwen/Qwen3-0.6B). Text-generation-free: reads the next-token distribution.
  • OpenAIBackend — any OpenAI-compatible logprobs endpoint (DeepSeek, OpenAI, vLLM, ...). Stdlib only.
  • GoogleBackend — Google Gemini, reading logprobs from generateContent. Stdlib only.
  • AnthropicBackend — Claude, which has no logprobs API, so it elicits an explicit JSON probability per label via structured output (pip install 'choiceone[anthropic]').

The logprobs backends (OpenAIBackend, GoogleBackend) score a single content token, so they support up to 10 options and yes/no.

Embed your own AI by subclassing Backend and implementing three methods:

from choiceone import Backend

class MyBackend(Backend):
    def build_prompt(self, user_content): ...
    def count_tokens(self, texts): ...
    def probs_over_labels(self, prompts, labels_per_prompt): ...

MLflow tracing

choiceone ships a first-party MLflow integration (pip install 'choiceone[mlflow]'). It records a choiceone.decision span for every call, with a nested choiceone.backend LLM span for the model seam:

import mlflow
from choiceone import ChoiceOne
import choiceone.mlflow

mlflow.set_tracking_uri("http://localhost:5000")
choiceone.mlflow.autolog()

so = ChoiceOne(backend=backend)
so(state, questions)  # traced

mlflow.openai.autolog() does not trace choiceone: the hosted backends talk HTTP through stdlib urllib, not the OpenAI SDK. Use choiceone.mlflow.autolog() instead. Call autolog(disable=True) to remove the patches, or autolog(log_traces=False) to keep the integration configured without recording traces.

HTTP server

choiceone-serve --model Qwen/Qwen3-0.6B --port 8000
# POST /v1/choiceone  {"state": ..., "questions": {...}}

License

MIT

Metadata

Release files for choiceone 1.0.3

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

Source distribution (sdist)

Source distribution for choiceone 1.0.3
File Size Uploaded Provenance
choiceone-1.0.3.tar.gz 24.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 45.6 kB

Release files / choiceone-1.0.3.tar.gz

Download URL choiceone-1.0.3.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dc789f9cb8cf74496dbafabbc8d99e4da30b171cb012d44b7d80ef1d6a5d22cd
BLAKE2b-256 checksum
How to use checksums
5f693d7a004a41fe149bff3c69e3a6db3e8eeaceb75789a112c4b74d08cf49a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / choiceone-1.0.3-py3-none-any.whl

Download URL choiceone-1.0.3-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a262d50ee9ba19ccab4007ee886b58311f5dbd0d8c04611a6dee36b3118a6ad6
BLAKE2b-256 checksum
How to use checksums
29912516a499b4fc8c39dc07b60fb006e44822d5e8c4fc18d9df0fe502079c8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for choiceone 1.0.3

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.

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