Examples

Triage an incident step by step

Open in playground →

Each answer builds on the ones before it: the severity decides the rollback, and both shape the status message.

  • depends_on
  • Enum
  • Text

Challenges

  • The answers must agree with each other: whether to roll back depends on how severe it is, and the status message has to say what was decided.
  • With depends_on the fields are answered in order, each one seeing the answers before it, instead of three separate guesses that could contradict each other.
  • The status message is free text, and it still has to match the two typed answers before it.
import os
from typellm import TypeLLMClient

client = TypeLLMClient(api_key=os.environ["TYPELLM_API_KEY"])
response = client.generate(
    context="Alert at 14:02: checkout API error rate 38% (normal: under 1%) since the 13:55 deploy of payments-service v2.14. p95 latency 4.1 s. About 1,200 customers affected so far.",
    questions={
      "severity": {
        "type": "string",
        "enum": [
          "low",
          "medium",
          "high",
          "critical"
        ],
        "instructions": "How severe is this incident?"
      },
      "roll_back": {
        "type": "boolean",
        "depends_on": [
          "severity"
        ],
        "instructions": "Given the incident and its severity, should the deploy be rolled back now?"
      },
      "status_message": {
        "type": "string",
        "depends_on": [
          "severity",
          "roll_back"
        ],
        "instructions": "One sentence for the status page, saying what is affected and what is being done."
      }
    },
)
print(response)

Time 1.06 s · Cost $0.000009

Generation(
    result={
        'severity': 'critical',
        'roll_back': True,
        'status_message': 'We are experiencing elevated error rates and latency in the checkout process affecting approximately 1,200 customers, and we are immediately rolling back the recent payments-service deployment to restore service.',
    },
    thinking={},
    usage=Usage(input_tokens=179, thinking_tokens=0),
)