AI Engineer Portal
Your personal operating system for career transition.
Exercise
Transform JSONL trace logs into aggregated metrics
Transform JSONL Trace Logs into Aggregated Metrics
AI services emit structured logs for every LLM call: model used, input/output token counts, latency, feature name, and whether the call succeeded. These logs are the raw material for operational dashboards, cost attribution, and debugging regressions.
What to build
Implement aggregate_traces(lines: list[str]) -> AggregateReport that parses JSONL trace logs and produces a structured report.
Input format — each line is a JSON object with:
request_id: strmodel: strfeature: strinput_tokens: intoutput_tokens: intlatency_ms: intsuccess: boolerror: str | null
AggregateReport dataclass fields:
total_calls: intsuccess_count: intfailure_count: intsuccess_rate: float— rounded to 4 decimal placesavg_latency_ms: float— across all callsp95_latency_ms: float— 95th percentile latencytotal_input_tokens: inttotal_output_tokens: intby_model: dict[str, ModelStats]— per-model breakdownby_feature: dict[str, FeatureStats]— per-feature breakdown
ModelStats: call_count, success_rate, avg_latency_ms, total_tokens
FeatureStats: call_count, success_rate, avg_latency_ms, avg_tokens_per_call
Why this matters
Operational insight from trace data is one of the most direct ways to improve an AI system. Engineers who can write this transformation quickly can answer production questions in minutes instead of filing tickets to a data team.
Constraints
- Skip malformed lines (log a warning, do not abort).
p95_latency_msshould use numpy-free percentile computation.- All float fields rounded to 2 decimal places except
success_rate(4 places).
Data Transformation / medium / Step 9 of 16
Transform and summarize data safely
Think like an evaluation or trace pipeline: group clearly, preserve the data story, and make edge cases visible instead of clever.
- - Handles missing or noisy records predictably
- - Produces summary output that is easy to inspect
- - Would be safe to rerun in a script workflow
- - Do grouped metrics stay readable?
- - Would malformed rows be debuggable?
- - Did I choose names that explain the transformation?
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.