Design it step by step
Define roles before finding numbers
Invented email: invoice October 3, registration deadline October 8, list price USD 120, discounted price USD 90. Name deadline and payable amount explicitly; first position or largest amount does not establish role.
Extract candidates with spans
Retain IDs, offsets, exact text, and neighboring context. Choice selects a candidate or none. Identical numeric strings at different positions may have different roles; avoid losing span identity.
Ask only about semantic roles
The official pre-parsed approach selects from supplied candidates and copies the source value. Identify the stated deadline or payable price. Choose none if absent; do not invent a value or missing year.
Provide locale and reference time
03/04 can be ambiguous. Tomorrow requires message time, timezone, and a reference date. This example fixes 2026-10-02, giving October 3 in the local calendar. Preserve ambiguity when context is missing. Use Decimal and explicit currencies.
Validate and retain uncertainty
Use calendar libraries to reject impossible dates. Store raw spans alongside normalized values. Correct role selection does not resolve ambiguous formats or authorize payment. Test credits, fees, multiple currencies, and missing years.
Worked example · Invented by this site
| Observation | Judgment | Application action |
|---|---|---|
| USD 120 list / USD 90 discount | Select the payable candidate | Copy 90 with USD; no payment action |
| 03/04 without locale | Ambiguous date order | Keep raw text for review |
| Tomorrow; reference 2026-10-02 | Requires a local reference context | Resolve October 3 in code |
A copyable design draft
Original examples. JSON illustrates request or input structure; Python calculates invented scores without an API call. Verify current interfaces and task policy before integrating.
# Offline date arithmetic with an explicit reference date.
from datetime import date, timedelta
reference = date(2026, 10, 2)
print(reference + timedelta(days=1)) # 2026-10-03
# Candidate selection is a separate judgment, not performed here.
# Preserve timezone and source text when handling real messages.Design a decisionCommon mistakes
- Selecting the first number or largest amount.
- Inventing a missing year or currency.
- Dropping original text and span provenance.
TRY / THINK / COMPARE
Think first, then compare
03/04 has high role-selection confidence. Store April 3?
Show explanation
Not yet. Role confidence does not resolve date-order ambiguity. Obtain locale evidence or review.
Before handing it over
- Roles and none are defined.
- Candidates retain source spans.
- Year, timezone, currency, and locale are explicit.
- Invalid and ambiguous values go to review.
Common questions
Who performs date arithmetic?
Calendar libraries and code; the model reads roles or named parts.
What if the candidate finder misses the target?
Return none and improve retrieval; do not force a wrong selection.
Sources and further reading
Inspired by official patterns and Datawhale practice topics. Explanations, examples, and exercises are independently written. These are teaching designs, not live API runs or benchmarks.