Typed question structs for the TypeSafe API.
TypeSafe supports three question primitives that can be mixed freely in a single request:
ExTypesafe.Question.Noul— yes/no question, returns a probability 0–1ExTypesafe.Question.Choice— pick one from a set you define, returns the chosen option + probabilitiesExTypesafe.Question.Score— rate on a rubric you define, returns a probability-weighted value
Example
questions = %{
is_urgent: ExTypesafe.Question.noul("Does this convey urgency?"),
department: ExTypesafe.Question.choice(
"Which team should handle this?",
%{billing: "Payments, invoicing, refunds", technical: "Bugs, outages, integrations"}
),
frustration: ExTypesafe.Question.score(
"How frustrated is the customer?",
["Calm", "Frustrated", "Very angry"]
)
}
Summary
Types
@type t() :: ExTypesafe.Question.Noul.t() | ExTypesafe.Question.Choice.t() | ExTypesafe.Question.Score.t()
Functions
@spec choice(instructions(), map()) :: ExTypesafe.Question.Choice.t()
Builds a Choice question.
Parameters
instructions— What the model should decide. Can be a string or a structured map.criteria— Map of option name to rubric description. Usenilvalue for options needing no description.
Examples
iex> ExTypesafe.Question.choice("Which team should handle this?", %{
...> billing: "Payments, invoicing, refunds",
...> technical: "Bugs, outages, integrations"
...> })
%ExTypesafe.Question.Choice{type: "choice", instructions: "Which team should handle this?", criteria: %{billing: "Payments, invoicing, refunds", technical: "Bugs, outages, integrations"}}
@spec noul(instructions(), map() | nil) :: ExTypesafe.Question.Noul.t()
Builds a Noul question (yes/no).
Parameters
instructions— The yes/no question to evaluate. Can be a string or a structured map.criteria— Optional map with:trueand/or:falsekeys describing what each means.
Examples
iex> ExTypesafe.Question.noul("Does this convey urgency?")
%ExTypesafe.Question.Noul{type: "noul", instructions: "Does this convey urgency?", criteria: nil}
iex> ExTypesafe.Question.noul("Is this spam?", %{true: "Clearly promotional", false: "Legitimate message"})
%ExTypesafe.Question.Noul{type: "noul", instructions: "Is this spam?", criteria: %{true: "Clearly promotional", false: "Legitimate message"}}
@spec score(instructions(), [String.t()]) :: ExTypesafe.Question.Score.t()
Builds a Score question.
Parameters
instructions— What the model should rate. Can be a string or a structured map.criteria— Ordered list of level descriptions (2–10 levels, low to high).
Examples
iex> ExTypesafe.Question.score("How frustrated is the customer?", ["Calm", "Frustrated", "Very angry"])
%ExTypesafe.Question.Score{type: "score", instructions: "How frustrated is the customer?", criteria: ["Calm", "Frustrated", "Very angry"]}