/dak:notebook-guidancefrom dak
Guides Jupyter notebook creation for data analysis, exploration, and visualization with BigQuery. Covers best practices for execution, validation, library installation, and structuring notebooks for clarity.
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.
None: SKILL.md is the whole skill.
Before choosing to use a notebook, evaluate the task complexity using these heuristics.
Use a notebook if you meet at least one of these criteria:
Do NOT use a notebook ONLY if:
Golden Rule of Data Storytelling: If any analytical insight, trend, or comparison is involved, favor a notebook and a visualization. A notebook is the "standard" environment for our developer workflow; do not avoid it because of "overhead".
[!CAUTION]
ALL DISCOVERY HAPPENS IN-CELL: Schema inspection, data preview, package availability, and model testing MUST be executed entirely inside notebook cells. Do not run shell commands, external SQL tools (
execute_sql,execute_sql_readonly), or separate Python scripts/environments to test code before creating cells.
[!IMPORTANT]
Agent execution rules: Your behavior MUST depend on whether the
notebook_execute_celltool is available in your current context: * If notebookexecute_celltool is available: You MUST follow the incremental GENERATE CELL -> EXECUTE CELL -> VALIDATE flow. * If notebookexecute_celltool is NOT available: You MUST generate the complete notebook and request user execution.
execute_cell tool is available: Follow the STEP BY
STEP GENERATE CELL -> EXECUTE CELL -> VALIDATE OUTPUT flow. Generate
ONE cell, execute it, then verify the output. If the output is data
(e.g. a dataframe), you MUST inspect it to confirm the logic is correct
before generating the next step. Batch generation of an entire notebook
is strictly prohibited because error propagation in notebooks is
expensive to fix.execute_cell tool is NOT available:
@skill:discover-assets or BigQuery list tools
to find the correct project.dataset.table before writing ANY code. If the
table ID is missing, ask the user.replace_cell (or delete failed attempts)
before presenting the notebook to the user, rather than pre-testing code
outside the notebook.%%bqsql magic cell followed immediately by a Python visualization
cell for those results). Use descriptive markdown cells to separate and
document different logical sections.Notebooks run in specific Kernels (execution backends). You MUST ensure the
kernel’s Python environment contains the necessary libraries (bigframes,
ipykernel, etc.).
ManagedSparkSession or DataprocSparkSession, indicates Local
Python.metadata.kernelspec notebook field. A Remote Spark
kernel name starts with a connection hash.@skill:managing-python-dependencies to verify if
a virtual environment exists. If not, create one. Ensure ipykernel is
installed in that environment. Install any other relevant libraries.[!IMPORTANT]
HARD STOP on kernel failure: If a cell execution returns "no active kernel" or any kernel-not-found error, you MUST stop immediately. Do NOT scaffold, generate, or insert any further cells. Inform the user which kernel is needed (e.g., PySpark / Dataproc Serverless) and wait for explicit confirmation that a kernel is active before proceeding with notebook execution.
Before installing any python libraries, you MUST use
@skill:managing-python-dependencies to detect how python dependencies are
managed in the project.
Since these are often ephemeral or managed by GCP:
%pip install cell, run
%pip list or import <package> to confirm the package is not already
present. Managed runtimes (Dataproc Serverless, Colab) pre-install many
common packages. Only install what is confirmed missing.%pip install <package> in the first cell if a package is confirmed
missing and it's the only way to modify the runtime.When in doubt about the kernel type or preferred installation method, ask the user for clarification.
Guidelines for performing exploratory data analysis, data cleaning, and visualization in notebooks.
The notebook should read like a story. While you have flexibility (e.g., multiple visualizations for one data cell, or data cells building on each other), aim for this general flow:
# Retention Analysis)## Exploring User Retention)%%bqsql
magics)
df.head() or assert sanity checks.df.plot()).Repeat steps 2-5 for each new sub-topic or insight. You can have multiple Data cells before a Visualization, or multiple Visualizations from one Data cell. The key is to keep them grouped logically and separated by Markdown headers.
Final Summary (Markdown Cell)
Next Steps: After the notebook has been successfully executed and verified, and the summary is complete, notify the user and propose next step suggestions.
When a notebook cell execution tool is available (exposed as
notebook_execute_cell or notebook__execute_cell), you MUST use it to
create and execute cells one at a time. You MUST NOT generate .ipynb files
programmatically (for example with nbformat) or execute notebooks in batch
from the shell (for example jupyter nbconvert --execute or papermill).
For Local Python execution, you MUST use a virtual environment and the Python version inferred from the kernel definition.
[!CAUTION]
When a cell fails, the agent MUST follow the protocol below. The agent MUST NEVER silently work around failures by fabricating data, substituting models, or changing infrastructure. Fake outputs that look correct are worse than a visible error.
Retry the cell once only if the error is plausibly transient (timeout,
DEADLINE_EXCEEDED, UNAVAILABLE, kernel restart, rate limit). Re-invoke the
cell execution tool with the exact same parameters: do NOT edit the code, change
the kernel, or alter any tool argument first. If it fails again with the same
or substantially similar error, the failure is confirmed. For deterministic
errors (SyntaxError, NameError, ModuleNotFoundError, PERMISSION_DENIED,
NotFound) skip the retry entirely. Proceed to step 2.
[!WARNING]
Before retrying, you MUST consider whether the cell is safe to re-run. If the cell has side effects (writes or appends to a table or bucket,
INSERT, DDL, an incrementing counter, a mutating API call) it may have partially succeeded before failing. In that case you MUST NOT blindly retry: report the situation to the user, or first verify or undo the partial effect.
Categorize the confirmed failure to determine whether the agent is allowed to fix it autonomously:
SyntaxError, NameError, typos in column names, wrong API
usage.ModuleNotFoundError, ImportError.@skill:managing-python-dependencies.The following actions are strictly forbidden as remediation for a failing cell. Violating any of these produces misleading outputs that the user cannot trust.
spark.createDataFrame(...) or
pd.DataFrame(...) with made-up rows as a substitute for real data sources.RandomForestClassifier for XGBClassifier) just to make the cell
pass.master("spark://...") → master("local[*]"). Never replace gs:// /
s3:// paths with local filesystem paths. Never swap a remote database
connection for a local file.LIMIT clauses,
filter predicates, or sampling to work around timeouts or resource errors
without explicit user approval.When a failure falls into a "STOP" category above, the agent MUST:
gcloud storage ls gs://foo-bucket/
and that your account has storage.objectViewer on it").Refer to the following resources for guidance on specific notebook topics:
Use BigFrames magics %%bqsql for BigQuery SQL queries. These cells support
native BigQuery SQL execution and data export to BigFrames dataframes.
[!IMPORTANT]
- Unless specified by the user, always use SQL for querying BigQuery.
- DO NOT use the standard BigQuery Python client library (
google.cloud.bigquery) orpandas.read_gbq.- Mandatory dataframe export: Always provide a dataframe name e.g.
%%bqsql <df_name>. This makes it easy to use results in follow up Python cells.- Verify that
bigframesversion number2.38.0and above is installed in the notebook runtime environment. If it is missing, ask the user if they would like you to upgrade for them.
Example %%bqsql magic usage:
# Initialize BigFrames and load %%bqsql magics
import bigframes
import bigframes.pandas as bpd
%load_ext bigframes
[!CAUTION]
Always use
%load_ext bigframesexactly as shown. Do not load submodules — for example,%load_ext bigframes.magicsor%load_ext bigframes.bigqueryare not valid and must not be used.
[!IMPORTANT]
The
bigframeslibrary must be installed.
%%bqsql df_sample
SELECT * FROM `project.dataset.table` LIMIT 10
[!CAUTION]
- NO Python SDK for Queries: Do not switch to
client.query(sql).to_dataframe()if SQL fails. Fix the SQL syntax instead.- NO Mixing Logic: Do not put Python code in the same cell as
%%bqsqlmagics.- NO Unbundled Micro-Testing: Do not issue individual shell commands per check or run out-of-band diagnostic scripts. Minimize how often you need to ask the user for permission.
Magic cells with %%bqsql <df_name> produce a BigQuery DataFrame. In
subsequent cells, you can use <df_name> directly.
[!IMPORTANT]
You MUST use BigFrames for data exploration, manipulation, splitting etc. You MUST use BQML SQL or bigframes.ml for machine learning tasks. You MUST NOT use pandas or Scikit-learn.
.to_pandas(): You MUST NOT use .to_pandas() to download the
entire dataset into memory. There are some exceptions:
to_pandas().to_pandas()read_gbq() for SQL: Do not write SQL queries and execute them
with read_gbq(). Use BigFrames Dataframe/Series methods instead.bigframes.ml.df.col.str.*, df.col.dt.*) over
remote UDFs.Series.map() or DataFrame.apply()..dtypes after loading, and use display() with .head() or .peek().model.to_gbq(). To load a
persisted model, use bpd.read_gbq_model().Integration with machine learning workflows and best practices. - Guide: Use
@skill:ml-best-practices. - MUST READ WHEN: The task involves machine
learning, training a model, clustering, classification, regression, or
time-series forecasting.
If any "MUST READ WHEN" condition is met, you MUST read the corresponding guide before proceeding.
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