Data platform support teams face a steady stream of partner requests, and Spark can be difficult to troubleshoot, especially for newcomers. Profirovic envisioned an agent that could answer why a job failed with an evidence-backed report and fixes grounded in the job context, available where users work, such as Slack or Airflow.
Medic for Apache Spark - First Aid for Failing Jobs
Speaker
Staff engineer Drasko Profirovic of Pinterest explains how the AI Engineer team built Medic, an agentic tool for diagnosing Apache Spark job failures.
The first prototype exposed data through MCP tools, then used one ReAct agent and a single prompt to guide analysis and report writing. Beta trials revealed inconsistent responses, prompt interactions, context limits, and weak regression testing. The team added OpenTelemetry traces in Langfuse and a test harness that records real tool responses as fixtures, replays them, and scores reports with offline evaluations.
Regex filters for noisy exceptions did not scale, so the team built a classifier that identifies exceptions common in successful jobs, fingerprints and clusters them, and ranks candidates by relevance and timing. The agent can retrieve truncated top exceptions or full details for a selected one. For metrics, a sub-agent turns time series into annotated graphs, giving the model a fixed-size visual summary even for long-running jobs.
The team replaced its single ReAct agent with a LangGraph Deep Agents architecture, assigning each agent its own prompt and subset of MCP tools. A supervisor classifies the request, triage checks job state, research agents investigate failure hypotheses in parallel, and a healer suggests fixes using runbooks in a vector database. The modular prompts also made it easier to add Spark SQL optimization support.
Profirovic says the multi-agent design gave the team more control, while better log handling substantially reduced inaccurate root causes. LangGraph workflows proved more brittle than the reasoning-and-acting approach in their trials. The team is exploring feedback from prior sessions and sees potential to apply the pattern to Flink and Trino.
Takeaways
- Use recorded production tool responses as fixtures so diagnostic behavior can be replayed and evaluated for regressions.
- Give each agent a focused role, prompt, and tool set to make behavior easier to maintain and test.
- Reduce log noise before asking an LLM to investigate, since common benign exceptions can misdirect its analysis.
- Summarize long time series as annotated graphs to control context use while preserving operational signals.
- Treat remediation advice as part of diagnosis and ground it in runbooks and job-specific evidence.
Mentioned in this talk
Search inside this talk
What was claimed 11
- works atDrasko Profirovic works at
Pinterest
Staff Engineer“I'm a staff engineer at Pinterest.”
YouTube Verified2 sources· Talk, Web· archived
- built
“our agentic diagnostics tool built to troubleshoot Spark failures”
YouTube Unverified1 source· Talk
- feature
Medic for Apache Spark: Investigates Spark job failures and suggests fixes grounded in job context.
“get back a deep research document that provides evidence on the root cause”
YouTube Unverified1 source· Talk
- integrates with
Medic for Apache Spark integrates with MCP
“We started by exposing our data resources by way of the Model Context Protocol”
YouTube Unverified1 source· Talk
- integrates with
Medic for Apache Spark integrates with
Langfuse
“We used OpenTelemetry to publish traces to Langfuse.”
YouTube Unverified1 source· Talk
- uses
“We used OpenTelemetry to publish traces to Langfuse.”
YouTube Unverified1 source· Talk
- featureEnd-to-end test harness: Records downstream tool responses as fixtures and replays them for report evaluation.
“In record mode, the agent calls real downstream systems, and tool responses are captured as fixtures.”
YouTube Unverified1 source· Talk
- built
“Instead, we built an exception classifier pipeline.”
YouTube Unverified1 source· Talk













