/dak:gcp-sparkfrom dak
Authors, optimizes, and runs PySpark/Spark code on Google Cloud Dataproc (serverless, clusters, Spark Connect). Handles ETL, ML, and SQL queries across GCS, BigQuery, Spanner, and multi-cloud storage.
Ships in dak. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
[!IMPORTANT]
You MUST follow the Task Execution Workflow when writing spark code.
[!CAUTION]
When the task is to generate a Spark notebook (as opposed to executing one), you MUST NOT modify your own local execution environment (i.e. do not run these commands with your shell or other tools). Specifically:
- NEVER create a virtual environment (
python -m venv,virtualenv,conda create,uv venv,poetry init/install, etc.).- NEVER install packages (
pip install,%pip install,uv pip install,conda install,poetry add).- NEVER run environment discovery loops such as activating a venv,
pip list, or probing foripykernel/google-cloud-spark-connectas a precondition for writing the notebook.Assume the user will select the appropriate kernel and dependencies after the notebook is generated.
Understand user request:
New Spark notebooks target the Local Python kernel and connect to
Managed Spark Serverless with ManagedSparkSession (Spark Connect); do
NOT ask the user which kernel to use. Only when the prompt explicitly
asks for a Remote Spark kernel or to run against a Dataproc
cluster, skip session initialization and use the pre-initialized
spark variable. Use the Runtime Profile (formerly Session Template)
named in the prompt; otherwise ask the user which one to use (scan for
existing ones with
gcloud dataproc session-templates list --location=<REGION>). Local
Python notebooks MUST start with these two cells (plain constants; no
os.environ, no Session() objects):
PROJECT_ID = "<PROJECT_ID>"
REGION = "<REGION>"
RUNTIME_PROFILE = "<RUNTIME_PROFILE_ID>"
# %pip install -U 'google-cloud-spark-connect[client,interactive]~=2.2'
from google.cloud.managed_spark_connect import ManagedSparkSession
spark = (
ManagedSparkSession.builder
.projectId(PROJECT_ID)
.location(REGION)
.runtimeProfile(RUNTIME_PROFILE)
.getOrCreate()
)
Understand schemas: ALWAYS use @skill:discover-assets skill or
references/schema_direct_inspection.md to understand input and output
schemas. Include the schema in your thought process BEFORE generating any
code. Do NOT guess column names. Cap GCP data asset discovery attempts at
3 retries max. Unless explicitly specified, assume that the assets are
located in the same project. Avoid scanning for assets across other projects
as it can take a long time. If an expected dataset or table does not exist,
use @skill:discover-assets to discover all similar tables in the namespace
or project.
MISSING SOURCE RULE: If the request does not name a table, GCS path or
catalog (or a required database instance/connection or s3a:// / abfss://
/ wasbs:// / wasb:// URI), you MUST run at most ONE
@skill:discover-assets search. If it does not return a single clear match,
you MUST list the candidates, ask the user which source to use, and STOP.
You MUST NOT infer the source by listing buckets, reading existing notebooks
or scripts, or running SHOW NAMESPACES / SHOW TABLES.
MINOR TYPO RULE: If there is a minor singular/plural or 1–2 character typo
in a table name (e.g. employees vs employee, or loans vs loan),
immediately fix the table name in code and proceed without asking for user
confirmation, noting the correction in your response.
STRICT HALT RULE: If the discovered table names differ from the requested table by more than a minor typo (e.g. completely different words, prefixes, or suffixes), you must IMMEDIATELY report the missing table and a neutral list of all available alternatives in the same namespace to the user without making any recommendations. You MUST ask the user which alternative to use and then STOP EXECUTING your turn. Do NOT write any Spark code or notebooks. Do NOT proceed with code generation, do NOT add fallback logic to code, and do NOT automatically substitute any alternative table (even if its schema seems to match) without explicit user permission.
Verify source accessibility: For Google Cloud Storage (gs://) paths,
verify access/existence using gcloud storage ls gs://<path-to-dataset>
(skip gcloud storage ls for external cloud URIs such as s3a://,
abfss://, wasbs://, or wasb://, which are accessed directly by Spark's
Hadoop FileSystem connectors). If accessing or reading a GCS path fails with
a storage error e.g., permission errors like
403 Forbidden/Forbidden/PermissionDenied, or location errors like
404 Not Found/NotFound/FileNotFoundException you should report the
error immediately. Either (1) ask the user what to do next, or (2) if asked
to execute a notebook, save the notebook with the error output and recommend
next steps to resolve the issue. Do NOT scan all buckets for alternative
fallback datasets when encountering GCS errors. NEVER create a new GCS
bucket (gcloud storage buckets create) without explicit user confirmation;
if a required bucket does not exist, STOP and ask the user.
Generate spark code:
Output Format: ALWAYS generate code in Python Notebooks
(.ipynb) format unless a standalone script or batch/cluster job is
explicitly requested: generate a Python script (.py) when a PySpark
script/job is requested, or a Spark SQL script (.sql) when a Spark SQL
script or spark-sql job/batch is requested (refer to
references/gcloud_dataproc.md for spark-sql syntax and submission).
Spark Session Initialization:
[!IMPORTANT] Initializing a Spark session on Google Cloud can take 2-3 minutes. You MUST inform the user about the potential delay.
[!CAUTION] You MUST NOT create a local Spark session. The following are BANNED: -
SparkSession.builder.master("local")-pyspark.sql.SparkSession.builder.getOrCreate()in notebooks or local Spark Connect scripts - Anytry/exceptfallbacks that revert to a localSparkSession- Silently switching execution modes when an explicitly requested mode fails (e.g. falling back from Spark Connect / interactive session togcloud dataproc batches submitor cluster creation without asking the user).
- Remote Kernel Notebooks (
.ipynb):sparkis pre-initialized; use it directly without callingManagedSparkSessionorSparkSession.builder.getOrCreate().- Local Python Notebooks (
.ipynb) & Spark Connect scripts: You MUST useManagedSparkSessionfromgoogle-cloud-spark-connectto connect to Managed Spark Serverless.- Dataproc Batch & Cluster jobs (
.pysubmitted viagcloud dataproc batches submit pysparkorgcloud dataproc jobs submit pyspark): Use standardSparkSession.builder.appName("<APP_NAME>").getOrCreate()(never.master("local")).
Refer to references/gcloud_dataproc.md for detailed configuration.
Minimal initialization for Local Python notebooks / Spark Connect:
from google.cloud.managed_spark_connect import ManagedSparkSession
spark = (
ManagedSparkSession.builder.projectId("<PROJECT_ID>")
.location("<REGION>")
.getOrCreate()
)
Production Logging: In standalone production PySpark batch jobs and
scripts (.py), you MUST use the standard Python logging module
instead of print() statements for job lifecycle, progress, and record
counts. Do NOT use the logging module in notebooks (.ipynb); use
print(), .show(), and standard cell outputs instead. Configure
logging for .py scripts with timestamps:
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
)
Security & Dynamic Variables: You MUST NOT hardcode plaintext
credentials, passwords, or tokens (use Secret Manager — refer to
references/jdbc_cloudsql.md when retrieving credentials from Secret
Manager). You MUST NOT hardcode environment-specific variables;
parameterize project IDs, dataset IDs, table names, and bucket paths via
os.environ.get(...) or arguments.
Missing or Inaccessible Custom JAR Rule (Do Not Improvise):
gs://.../*.jar URI (e.g., JDBC driver or
Socket Factory Uber JAR) is not provided by the user, or if
Spark session/job execution fails because the JAR does not exist
or is inaccessible in GCS, you MUST STOP and ask the user for
the gs:// JAR URI(s)..jar
files, download JARs from Maven Central (curl/wget) to upload to
GCS, or substitute spark.jars.packages Maven coordinates.Read and Write data: ALWAYS load only the connector reference file(s) needed for the prompt:
references/read_write_data.mdreferences/biglake_iceberg.mdreferences/spanner.mdreferences/jdbc_cloudsql.mds3a:// / S3-compatible object storage):
references/aws_s3.mdabfss://, wasbs://,
wasb://): references/azure_storage.mdMachine Learning Tasks: Refer to @skill:ml-best-practices skill
and references/ml_tasks.md when generating Machine Learning code.
Spark Optimizations & Broadcast Joins: ALWAYS refer to
references/spark_optimizations.md. When joining a large DataFrame with
a small lookup or dimension table, you MUST use broadcast()
(from pyspark.sql.functions import broadcast) on the small table.
Treat about 10 MB (Spark's default
spark.sql.autoBroadcastJoinThreshold) as a guide to what counts as
small, not a hard limit.
Verify schema before write: ALWAYS verify that the dataframe and
destination schema match, use df.printSchema() for dataframe schema and
refer to @skill:discover-assets skill or
references/schema_direct_inspection.md to verify destination schema.
Compile code before executing: For notebooks convert them to python
script using jupyter nbconvert --to script your-notebook.ipynb first. Then
compile the resulting python script using
python3 -m py_compile your-script.py. The same can be done for pyspark
source code (skip py_compile for pure .sql scripts).
Execute script or notebook: When requested to run a job, script,
session, or execute notebook cells against Managed Spark, refer to
references/gcloud_dataproc.md on how to execute code on Dataproc
Serverless using Spark Connect or Dataproc jobs.
Follow up with the user: If a brand new notebook was generated, instruct the user to select the appropriate kernel in the dropdown for cell execution.
[!CAUTION]
Ensure you verify this checklist to avoid mistakes
Before submitting a job, verify:
col, when, lit, broadcast, etc. from
pyspark.sql.functions)vector_to_array from correct module use
from pyspark.ml.functions import vector_to_array (NOT
pyspark.sql.functions)df.printSchema() before writingheader and inferSchema without these, the
header row becomes data and all columns are stringstoPandas() / collect()) NEVER call
.toPandas() or .collect() on raw or un-aggregated DataFrames. ALWAYS
perform transformations, aggregations (groupBy().agg()), or data reduction
(limit(), sample()) in Spark before converting small summaries to Pandas
for plotting or display.%pip install setup cell in generated notebooks is exempt). Pass
dependencies using --properties=spark.jars.packages=...,
--archives=gs://.../env.tar.gz#environment, --py-files, or a custom
--container-image.references/spark_optimizations.md and follow the confirmation protocol in
references/spark_refactoring_guide.md.read_file or generic full file reading tools on executed .ipynb
notebooks; they often contain massive base64-encoded image outputs that
cause excessive token consumption. You MUST inspect execution outputs with
cell-scoped reading tools (such as notebook__read_cell,
jupyter__read_cell, or specific line slices).The Managed Spark (Dataproc) service account needs:
roles/dataproc.worker: Job executionroles/biglake.admin: BigLake Iceberg table managementroles/bigquery.jobUser: BigQuery query materialization and load jobsroles/bigquery.dataEditor: BigQuery table reads and writes (direct and
indirect)roles/bigquery.readSessionUser: BigQuery Storage Read API session creationroles/storage.objectUser: Read/write GCS (data, Iceberg warehouse, and
--deps-bucket / temporaryGcsBucket)roles/spanner.databaseUser: Spanner reads and writesroles/secretmanager.secretAccessor: Accessing database passwords and
credentials stored in Secret ManagerRefer to references/gcloud_dataproc.md for detailed guidelines on managing
Spark clusters, jobs, batches, interactive sessions, and Spark Connect sessions.
For fleet-wide and multi-region observability — including active workload
inventory across Batches, Sessions, Clusters, and Jobs, failed batch discovery,
Serverless compute consumption (DCU-Hours and Shuffle-GB-Months), idle or
zombie cluster waste detection, scheduled pipeline cadence health, configuration
auditing, and Cloud Monitoring / Cloud Logging telemetry — use the
@skill:gcp-spark-observability skill.
Before submitting any Spark job or Dataproc batch, enforce the pre-submission
verification protocol in references/spark_refactoring_guide.md: inspect the
code for the anti-patterns catalogued in references/spark_optimizations.md and
obtain explicit user confirmation before applying refactoring.
For troubleshooting failed Spark jobs or Dataproc batches, inspecting/tailing
GCS driver output logs, analyzing Spark event logs, or performing Root Cause
Analysis (RCA), use the @skill:gcp-spark-troubleshooting skill.
references/aws_s3.md (opens in a new tab)references/azure_storage.md (opens in a new tab)references/biglake_iceberg.md (opens in a new tab)references/gcloud_dataproc.md (opens in a new tab)references/jdbc_cloudsql.md (opens in a new tab)references/ml_tasks.md (opens in a new tab)references/read_write_data.md (opens in a new tab)references/schema_direct_inspection.md (opens in a new tab)references/spanner.md (opens in a new tab)references/spark_optimizations.md (opens in a new tab)references/spark_refactoring_guide.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub googlecloudplatform/data-agent-kit-plugin --plugin dak41 skills in this plugin
/accidental-data-loss-prevention**STOP AND VERIFY**: Before running any command or tool that results in irreversible data loss, you MUST obtain explicit user consent.
When in doubt, ask. It is better to wait for confirmation than to accidentally delete production data or critical project assets.
Use this for:
- SQL: DROP TABLE/VIEW/SCHEMA/DATABASE, TRUNCATE, or broad DELETE (missing WHERE or using 1=1).
- Cloud Storage: gsutil rm or gcloud storage rm targeting production data or critical buckets.
- Infrastructure: gcloud projects delete, deleting Spanner/BigQuery/Dataproc resources, deleting secrets, or KMS key destruction.
/bigquery-ai-mlLeverages BigQuery's built-in machine learning and GenAI capabilities for advanced data analytics. Use when you need to write SQL queries that perform time-series forecasting, predict values, detect outliers or anomalies, find key drivers, perform semantic search or vector search, classify text, calculate similarity, summarize content, translate language, evaluate models, filter by semantic conditions, measure the causal effect of an intervention, compute correlations between columns, generate descriptive statistics and table distribution profiles, detect change points or structural breaks, extract trend or seasonality components, or leverage generative AI capabilities in BigQuery. Do not use for general BigQuery dataset, table, or job management requests.Other plugins' skills for the same job