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): ...

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.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 choiceone 1.0.2
File Size Uploaded Provenance
choiceone-1.0.2.tar.gz 21.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 39.4 kB

Release files / choiceone-1.0.2.tar.gz

Download URL choiceone-1.0.2.tar.gz
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
208cde9eff11797212658aaf185eb141d1e181ae46b5fa6eece1396f98c1d83f
BLAKE2b-256 checksum
How to use checksums
f4ea3e109218614df24215940a9adce9d5bf12f9d1fc55b9ff955d2d1e815108
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.2-py3-none-any.whl

Download URL choiceone-1.0.2-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e112d76b8c154a735d1cc16af0a924e8aaec0d4477f8168a8bf2cf618cd43d66
BLAKE2b-256 checksum
How to use checksums
9c48b6d4d5ac3963d80985a54d0d873d2d08d4f95d6cf42fd1e42538220f3f91
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.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.

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