Skip to main content
Glama

analyze_pyspark_source

Read-onlyIdempotent

Statically analyzes PySpark and DLT Python source code to detect Catalyst plan bloat, anti-patterns, skew risks, watermark reordering, and missing quarantine gates.

Instructions

Statically analyze PySpark or Delta Live Tables (DLT) Python source code for Catalyst plan bloat, anti-patterns, skew risks, watermark reordering, and missing quarantine gates.

Usage Guidelines:

  • Use for individual Python (.py) source strings or pipeline scripts.

  • For SQL queries or DLT SQL statements, use analyze_sql_source instead.

  • For scanning entire directories or multiple repository files, use scan_pipeline_directory instead.

Behavior:

  • Runs 100% offline via local Python AST inspection. Does NOT connect to Databricks clusters, execute code, or require JVM/cloud credentials.

  • Deterministic and idempotent. Returns a structured JSON report containing finding counts and diagnostic items.

  • Syntax errors or invalid Python constructs are surfaced as diagnostic findings rather than raising unhandled exceptions.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "source_code": "<source_code>"
    },
    "name": "analyze_pyspark_source"
  }
}

Input Schema

NameRequiredDescriptionDefault
file_nameNoOptional contextual filename for reporting (default: pipeline.py).pipeline.py
source_codeYesPython source code of the PySpark or DLT pipeline to audit.

Output Schema

NameRequiredDescriptionDefault
findingsYesList of diagnostic issues detected in the PySpark source.
file_nameYesContextual filename that was audited.
finding_countYesTotal number of diagnostic findings discovered.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changedv0.1.1
    • changedInput schema / properties / file_name / description
      Previous value: -"Optional filename context (default: pipeline.py)."New value: +"Optional contextual filename for reporting (default: pipeline.py)."
    • changedInput schema / properties / source_code / description
      Previous value: -"Python source code of the PySpark or DLT pipeline."New value: +"Python source code of the PySpark or DLT pipeline to audit."
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "properties": {
      +    "file_name": {
      +      "description": "Contextual filename that was audited.",
      +      "type": "string"
      +    },
      +    "finding_count": {
      +      "description": "Total number of diagnostic findings discovered.",
      +      "type": "integer"
      +    },
      +    "findings": {
      +      "description": "List of diagnostic issues detected in the PySpark source.",
      +      "items": {
      +        "properties": {
      +          "line_number": {
      +            "description": "1-based line number in source code.",
      +            "type": "integer"
      +          },
      +          "message": {
      +            "description": "Detailed explanation of the issue and production risk.",
      +            "type": "string"
      +          },
      +          "remediation": {
      +            "description": "Prescriptive remediation guidance or code fix.",
      +            "type": "string"
      +          },
      +          "rule_id": {
      +            "description": "Diagnostic rule ID (e.g., DD001, DD002, PERF001).",
      +            "type": "string"
      +          },
      +          "rule_name": {
      +            "description": "Human-readable diagnostic rule name.",
      +            "type": "string"
      +          },
      +          "severity": {
      +            "description": "Diagnostic severity level.",
      +            "enum": [
      +              "HIGH",
      +              "MEDIUM",
      +              "LOW",
      +              "INFO"
      +            ],
      +            "type": "string"
      +          }
      +        },
      +        "required": [
      +          "rule_id",
      +          "severity",
      +          "message"
      +        ],
      +        "type": "object"
      +      },
      +      "type": "array"
      +    }
      +  },
      +  "required": [
      +    "file_name",
      +    "finding_count",
      +    "findings"
      +  ],
      +  "type": "object"
      +}
  2. First observedv0.1.0

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond the annotations (readOnlyHint, openWorldHint=false, idempotentHint=true), it discloses that execution is fully local AST inspection with no cluster connection and no JVM/cloud credentials, which matters for an agent deciding whether it can call it without setup. It also documents the failure mode — syntax errors become diagnostic findings rather than raised exceptions — which annotations cannot express.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded purpose sentence followed by clearly labelled Usage Guidelines and Behavior blocks; every line carries distinct information (routing, offline execution, determinism, error handling) with no padding or restatement of the title.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a two-param read-only analyzer with a full output schema and rich annotations, the description covers scope, sibling routing, execution prerequisites, determinism, and error behavior. It also notes the report is structured JSON with finding counts and diagnostic items, which orients the agent despite the output schema existing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% and both properties are documented in the schema, so the schema is already doing the work. The description only implies the source_code payload via 'individual Python (.py) source strings' and adds nothing about the file_name reporting label, so the baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb ('Statically analyze') and a precise resource ('PySpark or Delta Live Tables (DLT) Python source code'), then enumerates what it detects (Catalyst plan bloat, anti-patterns, skew, watermark reordering, quarantine gates). An agent can distinguish it from the SQL and directory variants without opening any schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It states the input shape to use it for ('individual Python (.py) source strings or pipeline scripts') and explicitly names two alternatives with the condition that selects each: SQL input routes to analyze_sql_source, bulk repository scanning routes to scan_pipeline_directory. No inference is required.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.