Domdhi logoDOMDHI.OS
BACK_TO_COURSE

Build the Report

Four Ways a Correct-Looking Number Lies

Check These Every Time

The AI's query can run clean and still be wrong. These four catch most of it.

1. Averaging Averages

Department Calls Missed Rate
A 900 45 5.0%
B 100 30 30.0%
Both 1,000 75 7.5%

Average the two rates and you get 17.5%. Wrong by more than double, because B is tiny. Add up the counts first, then divide.

2. Time Zones

Many systems store time in UTC. A call at 9 PM Eastern on July 31 is stored as 1 AM on August 1. Forget to convert and it lands on the wrong day and in the wrong month.

3. Whole-Number Division

In Postgres and several other databases, dividing two whole numbers drops the fraction. 45 / 900 is 0, not 0.05. A missed rate of exactly 0% everywhere is the giveaway. The 100.0 below fixes it.

4. The Unfinished Day

It's noon. Today has half its calls. The chart shows a crash. Leave today off, or label it.

A Query That Dodges All Four

with callers as (
  select
    call_id,
    min(started_at) at time zone 'America/New_York' as local_time,
    bool_or(answered) as answered,
    max(wait_seconds) as wait_seconds
  from calls
  where direction = 'inbound'
  group by call_id
)
select
  local_time::date as day,
  count(*) as calls,
  count(*) filter (where not answered) as missed,
  round(100.0 * count(*) filter (where not answered) / count(*), 1)
    as missed_pct
from callers
where local_time::date < (now() at time zone 'America/New_York')::date
  and extract(isodow from local_time) < 6
  and local_time::time >= '08:00' and local_time::time < '17:00'
  and (answered or wait_seconds >= 5)
group by 1
order by 1;

Read it against the definition in the last lesson, line by line:

  • From outside: direction = 'inbound' stands in for it. Some systems mark calls between coworkers inbound too. If yours does, add a filter for them.
  • No person answered: records become callers, and a caller counts as answered if any phone was answered. Voicemail has to be saved as answered = false.
  • Weekday, 8 to 5 Eastern: the two lines after the date check.
  • Under 5 seconds left out: the last and.

Every word of the definition should have a line in the query. If one doesn't, the query is wrong.

For a week or a month, add up the calls column and the missed column, then divide. Never average missed_pct. That's lie number 1 all over again.

Make AI Attack Its Own Work

Assume this report is wrong. Give me the 5 most likely reasons,
and a query for each that would prove it.
Then build a 10-call test set where I can count the right answer
by hand, and run the report on it.

The 10-call test is hard to argue with. You count it on your fingers. Either the report matches or it doesn't.

QUIZ

Department A missed 45 of 900 calls. Department B missed 30 of 100. What's the overall missed rate?

Sign in to track lesson progress and earn a certificate.SIGN IN TO SAVE PROGRESS