Count failed training runs per project, keeping projects with zero failures
An experiment dashboard lists every project with its number of failed runs. Projects with no failures must still show up with 0, otherwise a healthy project looks like it vanished.
Write query() returning a SQLite SQL string. Tables: projects(id INTEGER, name TEXT) and runs(id INTEGER, project_id INTEGER, status TEXT) where status is 'done', 'failed' or 'running'.
Return (name, failed_runs) for EVERY project, where failed_runs counts its runs with status 'failed' (0 if none, including projects with no runs at all).
Order by failed_runs descending, then name ascending.
def query()Example
projects (1, 'llm'), (2, 'vision'); runs (1, 1, 'failed'), (2, 2, 'done'). Result: [('llm', 1), ('vision', 0)].
Understand the idea
A dashboard that lists projects with their failed run counts must still show healthy projects with 0. An inner join drops projects with no matching runs, so use a LEFT JOIN from projects to runs. Where you put the status filter matters: in the join condition, a non-failed run just fails to match, and the project still appears; in WHERE, the filter runs after the join and removes the project's row entirely. Worked example: projects (1, 'llm'), (2, 'vision'), (3, 'audio'); runs (1, 1, 'failed'), (2, 1, 'failed'), (3, 2, 'done'). llm has 2 failures. vision has only a done run, so 0. audio has no runs, so 0. Result [('llm', 2), ('audio', 0), ('vision', 0)], with ties sorted by name. Rule in words: left join runs on matching project id AND status = 'failed', count the run id column (COUNT of a column ignores NULLs, so unmatched projects get 0), group by project, sort by failed count high to low then name. Used for experiment tracking and CI health dashboards.
Similar problems
- Pick the best scoring model for each eval task with ROW_NUMBERMedium
- Pivot request statuses into columns with conditional aggregationMedium
- Find eval tasks where a candidate model scores below the baseline with a self joinMedium
- Keep every run in the top two distinct scores per project with DENSE_RANKMedium