Repository navigation
Analytics Internals
Checked against v0.7.6 on November 13, 2026.
This page describes what the analytics code computes, where each number comes from, and the rule that governs all of it: a figure derived from fewer than five observations is labeled insufficient and is never shown as if it were solid. It is for people who change kestrel/analytics/ or the pages that render it. For the learning loop that produces the outcome statistics, see Learning Loop Internals.
Analytics only reads the operator's own rows. It makes no network calls of its own, and it never contacts anyone or acts on a job site (hard rule 1 in CLAUDE.md). The one model call is the optional narrative described below.
Hard rule 6 in CLAUDE.md says sample sizes are always stated and any number from fewer than five observations is labeled insufficient. The code enforces it in several places, each with its own constant set to 5:
| Constant | File | Effect |
|---|---|---|
_MIN_N |
kestrel/analytics/metrics.py |
Applications per week and median first-response time stay None below five. quality.insufficient is true below five evaluations. |
_MIN_N |
kestrel/learning/outcomes.py |
A score band or a breakdown group with n < 5 has insufficient: true. A suggested ghosting threshold is None below five responses. |
_MIN_N |
kestrel/analytics/models_history.py |
Agreement rate and mean score error are None below five labeled evaluations. |
MIN_N |
kestrel/analytics/today.py |
The honest line on Today is marked insufficient below five outcomes. |
MIN_N, few()
|
kestrel/analytics/report.py |
The Analytics page: a rate over a base under five is dashed or labeled, whichever tile, table row or median it belongs to. few() is the one place that decides. |
The pattern is the same everywhere. The rate becomes None or carries insufficient: true, and the count it rests on is still returned so the page can say "3 of 5 needed" instead of hiding the number. Templates must render the count beside the rate. Do not round, interpolate or substitute a default for a missing rate.
Two other thresholds are looser on purpose and are not instances of the rule:
-
_MIN_OUTCOMES = 10inkestrel/analytics/summary.py. Below ten recorded outcomes on a track, the narrative is not requested at all and the page shows a code-built "too few to judge" message. -
_HONEST_SAMPLE_TARGET = 30inkestrel/analytics/today.py. This only scales the progress meter toward a sample large enough to carry a verdict.
If you add a new rate, give it its own count field, return None under five, and add a test beside the existing ones.
Two modules compute figures. kestrel/analytics/report.py builds what the Analytics page draws, for one track and one date range. collect_metrics() in kestrel/analytics/metrics.py builds the per-track metrics dict that the honest summary, the Today page's honest line and the MCP get_analytics tool read. They share the funnel's stage rank and the five-observation floor but not a query path, so a change to one figure usually needs a look at both.
build_report() in kestrel/analytics/report.py returns plain dicts, with a base (n or base) beside every rate. The page has one range for everything on it: 30 days, 90 days (the default) or all time (RANGES, normalize_range()), and each tile also carries the previous period's count when there is one. Everything is counted from one shared cohort so the tiles, the bar, the funnel and the tables agree:
- Roles (found, passed the rules, passed the quick check, fully read) are opportunities first seen in the range.
-
Pursuits (shortlisted onward) are pursuits dated in the range. A pursuit's date is when it was sent (
applied_at), else when it was first shortlisted (its first status event), else its last activity, else when the role was first seen. The cohort is therefore the applications sent in the period and everything that has happened to them since.
From that cohort it builds the tiles (a tile whose base is under five is dashed), where the applications stand now (offer, interviewing, waiting, turned down, no reply after 14 days, withdrawn, with consulting words on the consulting track), two funnel groups with their own scales (the role steps, then the pursuit steps), replies by fit score band, one table per grouping of where roles come from, reply timing and a waiting-age breakdown, and the weekly pace chart. Medians under five observations are None. plain_summary() builds the three code-written findings at the top of the page (Working, Not working and Worth changing) from the report's own counts, so there is an honest answer without a model. period_facts() hands the same range's counts to the P12 prompt, so the narrative names the same period the page shows. The page's exports (/analytics/export/numbers.csv, applications.csv and summary.pdf) are written through the desktop shell's Save dialog and send nothing anywhere.
collect_metrics() in kestrel/analytics/metrics.py assembles one JSON-able dict per track, with the sample size beside each figure. It returns the funnel, the score-versus-outcome analysis, four breakdowns, quality counters and time counters.
funnel() in kestrel/analytics/funnel.py has eleven steps:
ingested, tier0_pass, tier1_pass, tier2_evaluated, shortlisted, pursued,
first_response, screening, interview, final, offer
Each step reports count, sample_size (the previous step's count, which is the denominator) and conversion (count divided by sample size, None when the denominator is zero).
The first four steps come from the opportunity itself. _STAGE_RANK maps Opportunity.stage to how far it got through the gates: t0_pass and t1_reject reached the Tier 0 pass step, t1_pass reached Tier 1, and t2_done and t3_done count as past both. The tier2_evaluated count is the number of distinct opportunities with a Tier 2 evaluation. The remaining steps come from pursuits. Each pursuit is credited with every step up to the furthest one it reached, using a per-track status map (_PURSUIT_STEP), refined by Outcome.furthest_stage and by a recorded first response. This matters because a terminal status such as rejected or ghosted would otherwise hide how far the pursuit actually got.
The two halves are sourced independently, so a conversion can exceed 1.0. A role the operator shortlists by hand has no Tier 2 evaluation, which can make shortlisted larger than tier2_evaluated. The code leaves that visible and does not clamp it, because it means items entered a later step without being recorded at an earlier one. The funnel itself does not apply the five-observation floor. The step name and its sample_size are the honesty mechanism, and the page shows both.
This is the most important number on the page. analyze_outcomes() in kestrel/learning/outcomes.py joins each outcome to its latest Tier 2 evaluation and groups by score band: below 3.0, 3.0 to 4.0, 4.0 to 4.5, and 4.5 and up. For each band it counts how many outcomes received any response.
_discrimination() returns one of three states, and collect_metrics() passes it through unchanged:
-
None: fewer than two bands have five or more outcomes. The headline says there is insufficient outcome data. -
False: the score does not discriminate. The headline names the correlation and the spread in response rate across bands. -
True: the score discriminates.
The test for True has three parts. The point-biserial correlation between score and response must be at least 0.15 (_MIN_CORRELATION). The top usable band must convert at least as well as the bottom one. The spread between the best and worst usable bands must be at least 5 percentage points (_NONDISCRIMINATION_DELTA). The correlation requirement exists because a coin-flip response rate can produce a visible spread across bands at small sample sizes.
The same module also breaks response rates down by source, org size band, ownership and remote type, each group with its own n and insufficient flag, and reports furthest stage by band. Its suggested ghosting threshold is the 90th percentile of recorded days to first response, None under five responses.
quality_metrics() reports the override rate (verdict overrides divided by evaluations), the quarantine rate, tokens by tier, and a JSON validity rate. Validity is derived: evaluations divided by evaluations plus quarantines. It counts only Tier 1 and Tier 2 quarantines linked to an opportunity of the track, so quarantines from other tiers or without an opportunity (the analytics summary's own, for instance) do not depress a per-track rate. time_metrics() reports applications per week over the span of application dates, and the median days to first response.
kestrel/analytics/models_history.py feeds the Models page (kestrel/web/pages/models.py). model_summary() groups evaluations by tier, model and prompt version and computes mean score, verdict counts, mean latency, mean tokens, and, where the operator has labeled the same opportunity, agreement rate and mean absolute score error. Agreement is the one quality signal the model does not report about itself. Cost is only known for hosted sends, from frontier_transmission rows. A local model shows "local" and a hosted send with no reported cost shows "unknown". Neither is ever shown as $0.00.
bench_summary() in the same file reports the state of the gold sets that kestrel bench would use. The kestrel bench command itself persists nothing. The app's Model check, which queues a bench task that runs the same harness, does: each finished (step, model) result is written into the task payload so the task resumes after a restart, and the last 10 completed checks are kept in the setting bench.checks (kestrel/bench/check.py). Those stored checks are separate from model_summary(), which reads only evaluations and labels. See Benchmarking.
kestrel/analytics/progress.py and kestrel/analytics/run_summary.py derive the live scoring panel, the status rail and the last-run summary from existing rows (Run, ScrapeRun, Opportunity, Evaluation, Quarantine, Task). There is no event table, so a restart mid-run loses nothing (hard rule 5). These are raw counts. The one estimate, the minutes remaining, is withheld until at least five roles in the current batch have finished. kestrel/analytics/today.py builds the Today page columns, including honest_line(), which wraps collect_metrics() and never raises, so the landing page survives an analytics failure.
honest_summary() in kestrel/analytics/summary.py produces the narrative at the top of the Analytics page. Its design goal is that a self-reporting system must not always report good news. The verdicts are computed in code and the model only writes prose around them.
-
collect_metrics()gathers the numbers. - Code sets
discriminating(true, false orNone) andinsufficient(fewer than ten outcomes). - If the data is insufficient, or the caller passed no client, no model call is made. The result carries a code-built message from
_fallback_md(). - Otherwise the P12 prompt (
kestrel/llm/prompts/analytics_summary.v1.md) is rendered with the metrics as JSON and called through the same guard as every other prompt. See Prompts and Context Budgets. - If the call fails validation, the code-built message is returned. Nothing is invented.
- If the score is not discriminating or the sample is thin, the code-built finding is placed first in the narrative and becomes the headline, ahead of whatever the model wrote.
The P12 schema (P12Analytics in kestrel/llm/schemas.py) has summary_md, headline_finding, one_thing_to_change, evidence_for_it, sample_size_warnings and insufficient_data. The prompt tells the model to use only the supplied numbers, state the sample size for every claim, say plainly and first when the score does not discriminate, name exactly one thing to change, and say so when the data supports no conclusion. The prompt calls a sample under 10 "not yet meaningful", which is stricter than the five-observation floor in code.
The Analytics page (kestrel/web/pages/analytics.py) never calls the model on load. It shows the code verdicts at once, and POST /analytics/narrative (Rewrite summary) writes the narrative on request, so opening the page does not cost a billed call. When Tier 2 would run on an online model, the route first checks a confirmation from an ask-first dialog (GET /analytics/narrative/online) and sends nothing without it. The page has an outer try/except so a settings or database problem degrades to plain metrics plus a note instead of a 500. Under Hosted mode the summary call goes through run_prompt_hosted(), which redacts the confidential employer before anything is sent.
The MCP server exposes the same data through a get_analytics tool (kestrel/mcp/server.py), returning the funnel and score-versus-outcome parts with their sample sizes.
- Put the query in
kestrel/analytics/next to related ones, and read only existing rows. - Return the count the figure rests on in the same dict, under a name that says what it counts.
- Return
Nonefor the rate when the count is under five, and set aninsufficientflag. Do not return0.0. - If the metric feeds the narrative, add it to
collect_metrics()so it reaches P12, and check that the prompt's rules still hold for it. - Apply confidential-mode redaction at the data layer if the metric contains an organization name, as
kestrel/analytics/today.pyandmodels_history.pydo, so the REST and MCP surfaces cannot leak the current employer. - Add tests with fixtures under
tests/. Tests must not call a live job board, ATS or SEC endpoint.
Start here
Interfaces
Extending Kestrel
How it works
- Prompts and context budgets
- Document engine
- Learning loop internals
- Analytics internals
- Task queue and concurrency
- Database schema
Shipping and safety
- Packaging and releases
- Preflight and diagnostics
- Security and privacy model
- Outbound calls
- Benchmarking
Workarounds and Troubleshooting