Examples

Which date is earlier?

Open in playground →

A date comparison models often get backwards. With thinking on auto, the model decides it needs to think, and the earlier date comes back as one of the two strings, with a probability for each.

  • String enum
  • Thinking: auto
  • Probabilities

Challenges

  • Models tend to read xx/xx/yyyy as US month-first, so 07/06/2026 looks like July 6 and they pick June 8, 2026. Stating the format in the context is often not enough.
  • With "thinking": "auto", the field first gets a level of thinking for this call; this one gets some (thinking_effort reports it). The model then reads 07/06/2026 as day 7, month 6, puts both dates in the same form and compares them before it answers, and its reasoning comes back with the result.
  • return_probabilities works on enum and boolean fields, so the answer is a string enum of the two dates. It is always one of them, and each comes back with a probability.
import os
from typellm import TypeLLMClient

client = TypeLLMClient(api_key=os.environ["TYPELLM_API_KEY"])
response = client.generate(
    context="Two dates: June 8, 2026 and 07/06/2026. Dates written as xx/xx/yyyy are DD/MM/YYYY.",
    questions={
      "earlier": {
        "type": "string",
        "enum": [
          "June 8, 2026",
          "07/06/2026"
        ],
        "instructions": "Which date is earlier?",
        "thinking": "auto",
        "return_probabilities": True
      }
    },
)
print(response)

Time 1.88 s · Cost $0.000057

Generation(
    result={
        'earlier': {
            'value': '07/06/2026',
            'probabilities': {
                'June 8, 2026': 0,
                '07/06/2026': 1,
            },
        },
    },
    thinking={
        'earlier': 'We need answer user\'s simple question. Need produce final JSON. Need determine earlier date. Dates: June 8, 2026 and 07/06/2026 where xx/xx/yyyy is DD/MM/YYYY. 07/06/2026 = 7 June 2026. June 8 = 8 June 2026. Earlier is 7 June, label B. Output {"earlier": "B"}.',
    },
    usage=Usage(input_tokens=95, thinking_tokens=105),
    thinking_effort={
        'earlier': 'low',
    },
)