judgevet.domain.choice_options

Status: draft.

judgevet.domain.choice_options

Check Choice answers against the options their questions offered.

A Choice question offers the keys of its criteria. An answer whose choice or a probability key falls outside those keys cannot belong to the question, so the check rejects the response. Probability keys may cover a subset of the criteria. The options come from the question's criteria mapping, per https://docs.typesafe.ai/primitives/choice#structured-instructions-and-criteria.

Examples:

from judgevet.domain.answers import ChoiceAnswer
from judgevet.domain.choice_options import check_choice_options
from judgevet.domain.errors import JevResponseError
from judgevet.domain.questions import Choice

questions = {"queue": Choice(criteria={"billing": None, "technical": None})}
listed = ChoiceAnswer("billing", 1.0, {"billing": 1.0})
check_choice_options(questions, {"queue": listed})
off_list = ChoiceAnswer("sales", 1.0, {"sales": 1.0})
try:
    check_choice_options(questions, {"queue": off_list})
except JevResponseError as exc:
    assert exc.status_code == 200
else:
    raise AssertionError("an off-list option must raise")
See Also

check_choice_options(questions, answers)

Reject a Choice answer that names an option its question did not offer.

Answers with no matching question, non-Choice answers and questions without mapping criteria go unchecked.

Parameters:

Name Type Description Default
questions Mapping[str, Any]

Question names mapped to typed or raw questions.

required
answers Mapping[str, Answer]

Answer names mapped to parsed answers.

required

Raises:

Type Description
JevResponseError

If a Choice answer's choice or a probability key is not a criteria key of its question. The status code is 200.