DecisionModel accepts non-finite probabilities and undeclared choices

Open
#7,250 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
ai, backend

Research direction

Start with hindsight_api/engine/decision_model.py and trace how parsed DecisionResponse answers reach the decision code that applies choices and probabilities. Check the existing safe error or fallback behavior and any tests for malformed provider responses. Done means malformed answers are rejected or safely handled, while valid confidence: 0.0 remains accepted.

Written by the indexing model from the issue text.

Description

core

Bug description

DecisionAnswer accepts non-finite probability values and does not check that a choice belongs to the options declared for its question. It also accepts probability maps that omit options. Downstream decision code uses these values for ranking and gates without one shared structural validation step, so an invalid provider answer can influence a decision or fail inconsistently.

Minimal synthetic reproduction

from hindsight_api.engine.decision_model import DecisionResponse

response = DecisionResponse.model_validate({
    "answers": {
        "rank": {
            "choice": "not-an-option",
            "probabilities": {"o0": float("nan"), "o1": 0.7},
            "confidence": 0.9,
        }
    }
})
assert response.answers["rank"].choice == "not-an-option"

The current model accepts this payload. Replacing float("nan") with float("inf") is accepted as well; probabilities outside [0, 1] and partial maps are also representable by the model. This is an offline, synthetic reproduction and makes no provider request.

Expected behavior

Validate the parsed answer against its question before a caller applies it:

  • probabilities must be finite and within [0, 1] (and sum to one within a documented tolerance where the provider protocol requires it);
  • every expected option must be present, with no undeclared option keys;
  • choice must be one of the declared option IDs and, where applicable, agree with the probability ranking;
  • a structurally invalid answer should use the existing safe error/fallback behavior, not be applied as a decision;
  • confidence: 0.0 must remain a valid value.

This is structural validation only; it does not ask the engine to determine whether a model's valid answer is semantically correct.

Version and related work

Reproduced against v1.3.1; the same response model is present on main at 4b8dfb644c7ec568645fa58878c8b78424276189. Related but distinct: #7071 evaluates decision quality on partial numeric evidence; it does not cover malformed response validation.

Dominant language
Python
Stars
45.2k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vectorize-io/hindsight

All issues in vectorize-io/hindsight

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.