Skip to main content

Decision Types

Canonical Jev-style question constructors, typed answer models, Decision results, and shared state lowering.

Build question dictionaries with noul, choice, score, and box (or pass raw Jev-compatible dicts validated by norm_question). choice and score normalize inputs with listify and require at least two options or levels; noul accepts only 'true' and 'false' criteria keys.

Decision is a read-only Mapping over an AttrDict of typed answers (NoulAnswer, ChoiceAnswer, ScoreAnswer, BoxAnswer, RefusalAnswer) with attribute access (dec.q), bracket access (dec['q'], required when a question name collides with Decision or Mapping attributes), custom_dir tab-completion, and estimated USD cost. lower_state recursively converts aidialog.msg_parts Msg and Part objects plus nested JSON, omitting Thinking, Msg.raw, and UNSET while preserving JSON None and tool call IDs.

noul

def noul(
    instructions=None, # Yes/no question or statement to evaluate
    *, true=None, # Optional description of what counts as yes/true
    false=None, # Optional description of what counts as no/false
    criteria:dict=None, # Optional explicit `{'true': ..., 'false': ...}` mapping
)->dict:

Build a Jev noul (yes/no probability) question dictionary.

choice

def choice(
    criteria, # Mapping `{option: description_or_None}` or sequence of at least 2 option names
    instructions=None, # Question guiding the selection
)->dict:

Build a Jev choice (single-select classification) question dictionary.

score

def score(
    criteria, # Ordered rubric list of level descriptions, or `{label: description}` mapping
    instructions=None, # Question describing what to rate
)->dict:

Build a Jev score (ordered rubric rating) question dictionary.

box

def box(
    instructions=None, # Description of what to locate in the image (Jev 1.14+ only)
)->dict:

Build a Jev box (spatial bounding box) question dictionary.

score_criteria_list

def score_criteria_list(
    criteria
)->list:

Convert a score rubric (list or {label: description} dict) into an ordered list.

norm_question

def norm_question(
    q
)->dict:

Validate a question dict (or bare string shorthand for noul) and return a shallow copy.

NoulAnswer

def NoulAnswer(
    noul:float, # Probability of yes/true, in [0, 1]
    confidence:float=None, # Confidence in [0.5, 1]; defaults to `max(noul, 1 - noul)`
    raw:dict=None, # Original provider answer dict
):

Calibrated yes/no probability answer (type='noul').

ChoiceAnswer

def ChoiceAnswer(
    choice:str, # Selected option name
    confidence:float, # Confidence in [0, 1]
    probabilities:dict, # `{option: probability}` mapping
    raw:dict=None, # Original provider answer dict
):

Single-select classification answer (type='choice').

ScoreAnswer

def ScoreAnswer(
    score:float, # Expected score (probability-weighted average of zero-based rubric indices)
    confidence:float, # Confidence in [0, 1]
    probabilities:dict, # `{level_index_str: probability}` mapping
    legend:dict, # `{level_index_str: criterion}` rubric mapping
    raw:dict=None, # Original provider answer dict
):

Ordered rubric rating answer (type='score').

BoxCoordinates

def BoxCoordinates(
    top:float, bottom:float, left:float, right:float
):

Normalized bounding-box edges as fractions of image height/width in [0, 1].

BoxAnswer

def BoxAnswer(
    box, # `BoxCoordinates` or dict with `top`, `bottom`, `left`, `right`
    confidence:float=None, # Confidence in [0, 1], or None when omitted
    raw:dict=None, # Original provider answer dict
):

Spatial bounding-box answer (type='box').

RefusalAnswer

def RefusalAnswer(
    raw:dict=None, # Original provider answer dict
):

Per-question refusal answer (type='refusal'), returned by OpenAI when an individual question is refused.

norm_answer

def norm_answer(
    d:dict
):

Parse a canonical Jev-shaped answer dictionary into its typed answer object.

check_answers

def check_answers(
    answers:dict, # Normalized `{question_name: Answer}` mapping
    questions:dict=None, # Optional requested `{question_name: question}` mapping to verify completeness
)->dict:

Verify every requested question in questions has an answer, ordering by questions when given.

Decision

def Decision(
    model:str, # Model name returned by the provider (or requested when omitted)
    answers:dict, # `{question_name: Answer}` mapping
    usage:fastdecisions.utils.Usage=None, # Normalized token usage
    api_name:str=None, # Registered provider name, e.g. 'jev', 'gemini', 'openai'
    raw:dict=None, # Full provider response dict
):

Read-only mapping of normalized decision answers alongside model, usage, and raw metadata.

Decision.cost

def cost()->float:

Estimated USD cost using usage, get_model_info, and calc_cost.

lower_state

def lower_state(
    o, # Value, `Msg`, `Part`, or nested dict/list/tuple structure to lower to JSON-ready data
    on_media=None, # Optional callable `(p:Media) -> Any` returning a placeholder or `UNSET`; raises `ValueError` on `Media` when `None`
    *,
    drop_server_tools:bool=False, # Drop provider-executed `ToolUse(server=True)` parts and their matching `ToolResult`s?
):

Recursively lower aidialog Msg/Part objects into JSON-ready structures, returning UNSET for dropped items.