Spark SQL jobs became slow or failed as data grew, joins widened, and aggregations nested.

The lack of clear root-cause signals increased latency, over-provisioned clusters and cost.

The team solved it by: 👉 Expose structured SQL metadata with the open-source Spark MCP server. 👉 Use rule-driven prompts so the LLM only detects defined anti-patterns. 👉 Emit traceable JSON detections tied to stage, task and node IDs.

The parts that matter: 1️⃣ Spark MCP server - provides execution metadata, final and physical plans, and stage/task metrics 2️⃣ pattern-guided prompting - restricts the LLM to detect only pre-defined performance anti-patterns

Runtime dropped by 40 - 95% on long-running jobs and compute cost fell by 50 - 90%.

The approach requires maintaining a curated list of anti-patterns and tuning prompts, which adds engineering overhead. It also depends on accurate Spark MCP data; missing metrics can lead to false negatives. However, the saved debugging time outweighs the maintenance cost for large workloads.

What other Spark performance signals would you encode as LLM-detectable rules?