Structured output

Ask typed questions and get calibrated answers on every result, in the same call.

Add questions to any search and every result comes back with typed answers. No second LLM pass, no parsing prose: each answer is a probability, a choice or a score.

const res = await ts.search('el Presupuesto 2027', {
  mode: 'normal',
  questions: {
    mentions_figure: {
      type: 'boolean',
      instructions: 'Does the article mention a specific amount of money?',
    },
    stance: {
      type: 'choice',
      instructions: 'What is the article’s stance on the budget?',
      criteria: { supportive: null, critical: null, neutral: 'Reports without taking a side.' },
    },
    impact: {
      type: 'score',
      instructions: 'How much does it affect households?',
      criteria: ['None', 'Low', 'Moderate', 'High', 'Very high'],
    },
  },
});

const answers = res.results[0]?.answers?.values;

Question types

typecriteriaAnswer
booleanOptional: what counts as true and as false.probability that the statement is true.
choiceRequired: the options as keys, each with an optional description. At least two.The choice, the probabilities of every option and a confidence.
scoreRequired: the steps of an ordered scale, lowest first. At least two.An interpolated score on the scale, the probabilities of each step and a confidence.

Up to 8 questions per request. Keys are letters, digits, - or _, up to 40 characters.

Reading the answers

results[0].answers
{
  "basis": "article",
  "values": {
    "mentions_figure": { "type": "boolean", "probability": 0.93 },
    "stance": {
      "type": "choice",
      "choice": "critical",
      "probabilities": { "supportive": 0.07, "critical": 0.81, "neutral": 0.12 },
      "confidence": 0.81
    },
    "impact": { "type": "score", "score": 2.6, "confidence": 0.74 }
  }
}
  • basis says what the answer was based on: article when the article was read, headline when only the headline and standfirst were available. Use normal or deep if you need answers on the text.
  • A boolean probability between 0.35 and 0.65 means undecided, not a weak yes.

Answers are part of the response, so they are cached with it for 10 minutes. They are not reused across different questions.

On this page