DecisionModel accepts non-finite probabilities and undeclared choices

Aperta
#7,250 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
ai, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
45.2k
Fork
5.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vectorize-io/hindsight

Tutte le issue di vectorize-io/hindsight

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.