Report Daily LLM Spend and Invalid Output Rate per Project
Last updated: November 29, 2026
Quick Overview
Given a table of every LLM call made across client projects, write a SQL query that returns, per project and day for one week, the number of calls, total cost, provider errors, and the share of successful calls whose output failed schema validation.
Ode
November 29, 20260
0
0 solved
Given a table of every LLM call made across client projects, write a SQL query that returns, per project and day for one week, the number of calls, total cost, provider errors, and the share of successful calls whose output failed schema validation.
With many client systems calling models at once, Ode engineers need quick visibility into cost and output quality per engagement. This screen checks clean aggregation, conditional counting, correct denominators and safe division.
What the Interviewer Expects
- Group by project and calendar day
- Use conditional aggregation for errors and invalid outputs
- Use only successful calls as the denominator for the invalid rate
- Guard division by zero with NULLIF
- Use a half-open date range so the index on created_at is usable
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you add p95 latency per project and day?
- The client is in another time zone. How do you define a day?
- How would you flag days where invalid rate is more than double the trailing 7-day average?
- What index would you add for this query?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Table llm_calls(call_id, project_id, created_at TIMESTAMP, model, input_tokens, output_tokens, cost_usd NUMERIC, status TEXT, schema_valid BOOLEAN). status is 'ok' or 'error'; schema_valid i...
Approach
Filter to the week with a half-open range, group by project_id and the date part of created_at, and compute each metric with SUM(CASE ...). The invalid output rate is invalid successful calls di...