A delivery at 17:30 UTC in October is 18:30 in London, after the cut-off. Let a versioned deadline tool compute return windows and a reply guard check what the agent quotes.
The promise in a help-desk reply
Tanishka writes to the help desk at Belgavi's Book Store: a novel arrived with a torn cover, and Tanishka wants to know how long there is to send it back. The help-desk agent reads the case, sees the delivery event and replies: "You can return it until Friday 6 November."
That sentence is a commitment. If the warehouse later rejects a return on Saturday 7 November because the real deadline was Friday, nothing is lost. If the real deadline was Monday 9 November, the store has just told a customer there is less time than there really is. If it was earlier, the store has promised something its own returns system will refuse. Either way the reply is a piece of date arithmetic, and date arithmetic is exactly the kind of work that should stay deterministic when an agent joins a workflow.
The return policy at the store is short: requests are accepted until 23:59 store time on the 10th business day after delivery, and a parcel delivered at or after 18:00 counts from the next business day. Short policies hide several decisions: which time zone, which days are business days, which holidays, what "after delivery" means for a Saturday delivery, and in whose clock the customer should read the answer.
What goes wrong when the model does the arithmetic
A language model asked to compute this will usually produce something plausible. The problem is not that it is always wrong; it is that the errors are silent and cluster at edges that ordinary test conversations never hit. The companion example compares the deterministic tool with two shortcuts that people and models commonly take: "delivery date plus 14 calendar days" and "10 business days counted on the UTC date, ignoring holidays".
| Case | Delivered (UTC) | Tool deadline (store time) | Calendar-day shortcut | UTC business-day shortcut |
|---|---|---|---|---|
| CASE-2101, ordinary weekday | 23 Oct 2026 16:30 | Fri 6 Nov | 6 Nov | 6 Nov |
| CASE-2102, after the cut-off | 23 Oct 2026 17:30 | Mon 9 Nov | 6 Nov | 6 Nov |
| CASE-2103, June evening | 5 Jun 2026 17:30 | Mon 22 Jun | 19 Jun | 19 Jun |
| CASE-2104, year-end | 18 Dec 2026 10:00 | Wed 6 Jan 2027 | 1 Jan 2027 | 1 Jan 2027 |
The first row is why the shortcuts survive review: on an ordinary weekday all three agree. CASE-2102 was delivered at 17:30 UTC, which is 18:30 in London on 23 October because British Summer Time ends on 25 October. In store time the parcel arrived after the cut-off, so counting starts a business day later. The UTC shortcut compares the cut-off with the wrong clock. CASE-2103 is the same mistake in June. CASE-2104 crosses Christmas Day, the substitute Boxing Day holiday on Monday 28 December and New Year's Day; the calendar-day shortcut gives the customer five fewer days than the policy does.
The fifth case in the example uses the same delivery as CASE-2101, but the customer, Hansini, reads email in India. The deadline is 23:59:59 GMT on Friday 6 November, which is 05:29 on Saturday 7 November in Asia/Kolkata. A reply that says "Friday" is correct in London and misleading in Bengaluru.
Move the arithmetic into a tool
The fix is an ordinary design move: the agent stops computing deadlines and calls a tool that does. What makes it work is the contract of that tool.
def return_deadline(delivered_at_utc, business_days=10, calendar=STORE, customer_tz='Europe/London'):
if delivered_at_utc.tzinfo is None:
raise ValueError('delivered_at_utc must be timezone-aware')
store = ZoneInfo(calendar.tz)
local = delivered_at_utc.astimezone(store)
effective = local.date()
if not calendar.is_business_day(effective):
effective = calendar.next_business_day(effective)
elif local.time() >= time.fromisoformat(calendar.cutoff):
effective = calendar.next_business_day(effective)
d = effective
for _ in range(business_days):
d = calendar.next_business_day(d)
end_local = datetime.combine(d, time(23, 59, 59), tzinfo=store)
... # returns the rule, calendar version, counted days, store, UTC and customer-facing timesFour properties matter more than the loop itself.
- Inputs are instants, not dates. The tool takes a timezone-aware delivery time and refuses naive values. Converting to a date is the tool's job, done in the store's zone, because that is where the policy is defined.
- The calendar is data with a version. Holidays, weekends, the cut-off and the zone live in a calendar object whose version is a hash of all of them. The answer carries that version, so a dispute months later can be replayed against the calendar that was in force.
- The answer explains itself. The result includes the effective delivery date, any adjustment ("delivered at 18:30 store time, at or after the 18:00 cut-off"), the ten counted business days and the deadline in store time, UTC and the customer's zone. A person reviewing the case sees why, not just what.
- The customer-facing string is produced once. The tool returns
customer_text, for example "Saturday 07 November 2026, 05:29 (Asia/Kolkata)". The agent's job is to put that string in a sentence, not to rephrase it.
Keep the agent honest with a reply guard
Moving the arithmetic into a tool is not enough if the agent can still paraphrase the result or add its own reassurance. A small deterministic guard closes that gap: before a drafted reply goes to the customer, it must contain the tool's customer_text verbatim and must not contain any other date expression.
def check_reply(reply, tool_result):
quoted = tool_result['customer_text']
if quoted not in reply:
return False, 'the reply does not quote the deadline returned by the tool'
others = DATE_WORDS.findall(reply.replace(quoted, ''))
if others:
return False, 'the reply mentions other dates: ' + ', '.join(others)
return True, 'ok'In the example, a reply that quotes the deadline passes. A reply that adds "so any time before Friday 6 November is fine" fails, because "Friday" and "6 November" are not the tool's words. A reply that says "you have two weeks" fails because it never quotes the tool. A failed check sends the draft back to the agent with the reason, or to a person; it never reaches the customer.
The pattern rejects some harmless replies. "Please reply by Monday if you need a label" mentions a date that has nothing to do with the deadline. That is an acceptable cost for a help-desk flow, and the guard's pattern can be narrowed later with evidence from rejected drafts.
What stays deterministic, and what the agent still does
The division of labour is worth writing down, because it is the part a team argues about.
| Concern | Owner |
|---|---|
| Reading the customer message and finding the order | Agent |
| Deciding that the question is about the return deadline | Agent |
| Converting time zones, counting business days, applying the cut-off | Deadline tool |
| Holiday list and policy parameters | Calendar data, owned by operations |
| Wording of the reply around the quoted deadline | Agent |
| Whether the reply may be sent | Reply guard |
The agent keeps the parts where language is the problem: understanding a message that says "the cover is ripped, can I still send it back?", choosing the right order when the customer has three, and writing a reply in a friendly tone. Everything that has a correct answer computed from data moves out.
Migrating an existing flow
Most stores already have this logic somewhere, usually inside the returns service that accepts or rejects the request. The migration is mostly about exposing it, not rewriting it.
- Find the existing implementation and its tests. If the returns service already decides eligibility, the tool should call that code or share its library, so the help desk and the warehouse can never disagree.
- Extract the calendar into versioned data if it is hard-coded, and record the version on every eligibility decision.
- Expose a read-only tool with the contract above. Read-only matters: computing a deadline must not create a return.
- Add the reply guard to the agent's send path, and log every rejection with the draft and the tool result.
- Run the edge fixtures (cut-off in summer time, weekend delivery, the year-end holidays, a customer in a zone that changes the calendar date) as unit tests of the tool, not as prompts to the agent.
When you do not need an agent at all
If every question about deadlines arrives through a form with an order number, the reply is a template: look up the order, call the tool, fill in the date. An agent adds value only when the request arrives as free text, mixes several questions, or needs judgement about which order or item is meant. Measure how many deadline questions are already structured before putting a model in that path.
Failure modes and verification
- The calendar is wrong or stale. The tool will be confidently wrong. Load holidays from an authoritative list, review them each year and alert when the calendar has no entries beyond the next three months.
- Two implementations drift apart. If the warehouse and the help desk compute deadlines separately, they will eventually disagree. One library, one calendar version.
- Time zone data is old. Rules change; keep the IANA time zone database current on every host, and on Windows pin the
tzdatapackage. - Naive timestamps sneak in. Reject them at the tool boundary, as the example does, rather than guessing a zone.
The companion example checks all of these edges in nine unit tests, including a test that adding one holiday changes both the calendar version and the deadline.