gcloud CLI Safety Guardrails

gcloud CLI Safety Guardrails

Forces an agent to validate gcloud CLI syntax against live help output and apply safety guardrails and output reduction before proposing or running any Google Cloud command.

Skill files4 files

references/

SKILL.md306 lines
1
---
2
name: gcloud
3
metadata:
4
version: "1.0.4"
5
category: CloudInfrastructureAndServices
6
description: >-
7
Provides safety-critical validation, guardrails, and data reduction for gcloud
8
CLI operations across Google Cloud Platform (GCP) services and infrastructure.
9
Use when planning, generating, constructing, proposing, describing, or
10
executing any gcloud CLI commands - including when answering questions about
11
gcloud syntax, or formatting flags. Don't use when writing Google Cloud
12
client library code or raw REST/gRPC API requests.
13
---
14
15
# gcloud CLI Skill for AI Agents
16
17
> [!CAUTION]
18
>
19
> ### MANDATORY PRE-CONDITION: EXPLICIT LEAF-LEVEL SYNTAX VALIDATION
20
>
21
> All pre-existing knowledge of `gcloud` commands, flags, flag values, and
22
> positional argument syntax is **stale and prone to hallucination**.
23
>
24
> NEVER propose command parameters, output flag options, execute commands, OR
25
> outline step-by-step plans for any `gcloud` task before validating leaf-level
26
> syntax via `gcloud help <command>` (or including leaf-level help lookup as a
27
> mandatory step in the plan).
28
>
29
> **Mandatory Action Rules**:
30
>
31
> 1. **Direct Execution & Code Generation**: **ALWAYS** invoke `gcloud help
32
> <leaf_command>` (e.g. `gcloud help compute instances create` or `gcloud
33
> help sql instances create`) before proposing or executing the final
34
> command syntax, **UNLESS** the user prompt already provides `gcloud help`
35
> output, states to assume command syntax is already validated, or instructs
36
> not to execute any commands. When instructed not to execute any commands,
37
> **NEVER** invoke `run_command` (not even for `gcloud help` or directory
38
> listing commands like `ls`); read bundled reference files
39
> (`references/cli-usage.md`, `references/mcp-usage.md`, and
40
> `references/attribution.md`) directly with `read_file`.
41
>
42
> 2. **Planning & Strategy Queries**: When asked for a plan, strategy, or next
43
> steps to achieve a user goal (e.g., *"What is your plan to accomplish
44
> X..."*), the response **MUST explicitly include running `gcloud help
45
> <leaf_command>`** as Step 1 of the plan before proposing flags or
46
> executing commands.
47
>
48
> 3. **Non-Transitive Validation**: Parent command group help (e.g. `gcloud
49
> help compute`) is not sufficient for leaf-level syntax validation.
50
> Validation must occur at the specific leaf subcommand level.
51
>
52
> 4. **FORBIDDEN Web Search Fallback**: NEVER use `search_web`, web search, or
53
> external documentation search tools for gcloud CLI syntax. `gcloud help
54
> <leaf_command>` is the **EXCLUSIVE** authorized authority for command
55
> syntax.
56
>
57
> 5. **User Flag & Project Preservation**: When proposing intermediate command
58
> steps, **ALWAYS** preserve all user-specified flags (including
59
> `--project=<project_id>`) in the proposed response text.
60
>
61
> 6. **Mandatory Plan Template**: When generating a plan, the response **MUST**
62
> copy this exact 4-step structure:
63
>
64
> - **Step 1**: Syntax Validation via `gcloud help <leaf_command>`
65
> - **Step 2**: Parameter Verification (confirming required and optional
66
> flags, and explicitly checking if the `--dry-run` or `--validate-only`
67
> flag is supported)
68
> - **Step 3**: Dry-Run Command Proposal (If `--dry-run` or
69
> `--validate-only` is supported, there MUST be a `--dry-run` or
70
> `--validate-only` invocation before the next step.)
71
> - **Step 4**: Command Proposal & Authorization (If the command is on the
72
> "Prohibited Operations" denylist, state that autonomous execution is
73
> forbidden, and the user MUST be explicitly asked for authorization to
74
> proceed. If the command is NOT on the denylist, propose or proceed
75
> with execution, while following *ALL* "Execution Constraints" below.)
76
77
This document provides essential guidelines and best practices for AI agents
78
interacting with the Google Cloud SDK (`gcloud` CLI). Following these rules is
79
critical to avoid hallucinated commands, flags, flag values, and positional
80
argument syntax, prevent destructive actions, and minimize context window usage.
81
82
## Usage Attribution
83
84
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
85
MUST read and follow the instructions in
86
[Usage Attribution](references/attribution.md). If a more specific product or
87
domain skill (e.g., `cloud-run-basics`, `bigquery-basics`, `gke-basics`) is
88
also loaded or active for the current task, **ALWAYS** use that specific
89
skill's `skill:<name>` attribution tag instead of `skill:gcloud`. For commands
90
executed directly in the terminal when no product-specific skill applies (never
91
in generated scripts, Terraform, or user code), prefix `gcloud` with
92
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gcloud)"`
93
and append `agent-skills/1.0 (skill:gcloud)` to `User-Agent` headers.
94
95
## Execution Modes
96
97
AI agents can interact with Google Cloud resources in two primary ways:
98
99
- **Direct CLI Execution**: Executing `gcloud` commands directly in a local or
100
automated shell environment. See [CLI Usage](references/cli-usage.md) for
101
installation, authentication flows, and configuration management.
102
- **Model Context Protocol (MCP)**: Invoking structured tools via the Cloud
103
CLI remote MCP server (`run_gcloud_command`). See
104
[MCP Usage](references/mcp-usage.md) for tool schemas, parameter rules, and
105
server configuration.
106
107
## Core Principles
108
109
### 1. Explicit Command Validation (Mandatory)
110
111
* **Action**: **ALWAYS** call `gcloud help <command>` for the *exact* command
112
that is intended to be run (e.g., `gcloud help compute instances create`).
113
* **Verify**: Ensure the command, flags, flag values, and positional argument
114
syntax are valid for that specific leaf command before attempting execution
115
or presenting plans. Validation is not transitive from parent groups.
116
117
### 2. Data Reduction Strategies (Mandatory)
118
119
Minimize the volume of data returned by `gcloud` to save context window space
120
and reduce latency. DO NOT execute any `list` command without including at least
121
one data reduction flag (`--limit`, `--filter`, or `--format`).
122
123
* **Projection**: Use `--format="json(key1, key2, ...)"` to select only the
124
specific fields needed for the task. To understand the advanced projection
125
and formatting syntax, refer to `gcloud topic projections` and `gcloud topic
126
formats`.
127
128
* **Limiting**: Use `--limit=N` to cap the number of resources returned.
129
130
* **Filtering**: Use `--filter` to narrow down results server-side. Prioritize
131
`:` for pattern matching and never quote the right side of the colon. Treat
132
the entire filter flag as a singular string without quoting or escaping
133
characters. To study the filter expression syntax, refer to `gcloud topic
134
filters`.
135
136
* **Schema Discovery**: Unconstrained resource lists can quickly exhaust the
137
context window with redundant data. To prevent this, discover a resource's
138
schema before executing queries. If unsure of the JSON key path for
139
projecting fields (`--format`) or filtering (`--filter`), run the targeted
140
resource's list command (if supported) with a single-item limit:
141
142
```bash
143
gcloud <GROUP> <RESOURCE> list --limit=1 --format=json
144
```
145
146
Examine this single instance's JSON structure to safely identify the correct
147
schema keys before requesting full or filtered datasets.
148
149
### 3. Execution Constraints
150
151
* **Single Commands**: Execute a single `gcloud` command at a time. No command
152
chaining or sequencing.
153
* **No Shell Operators**: Do not use command substitution (`$(...)`), pipes
154
(`|`), or redirection (`>`, `>>`, `<`). This is to increase command safety
155
and ensure commands are more easily understandable and reviewable by users.
156
* **Non-Interactive Execution (`--quiet` / `-q`)**: Pass the `--quiet` (or
157
`-q`) global flag on all execution commands (e.g., `gcloud pubsub topics
158
delete temp-topic --quiet --project=test-project`). AI agents run in
159
headless, non-interactive environments without a TTY or `stdin` input
160
handler. Without `--quiet`, commands that prompt for user confirmation (such
161
as deleting resources, approving defaults, or selecting unspecified regions)
162
will pause execution indefinitely waiting for input, causing background task
163
timeouts. Including `--quiet` forces non-interactive mode, causing `gcloud`
164
to automatically accept safe default choices or fail immediately with an
165
explicit error if required parameters are missing.
166
* **No Blind Lists**: NEVER execute a `list` command without `--limit`,
167
`--filter`, or `--format`.
168
169
### 4. Project and Location Scoping (Critical)
170
171
To ensure commands are deterministic, non-interactive, and target the correct
172
environment, they must explicitly provide project and location scoping.
173
174
* **Explicit Project Target**: Do not rely on active configuration defaults.
175
Always append `--project=<PROJECT_ID>` to all resource-manipulating and
176
querying commands (unless running pure local config commands). This avoids
177
accidental execution against the wrong project.
178
179
* **Prevent Location Prompts**: Many Google Cloud resources are regional or
180
zonal. If the location flag is omitted (e.g., `--region`, `--zone`, or
181
`--location`), `gcloud` will trigger an interactive prompt to select a
182
zone/region. This violates the **No Interactivity** rule. Always provide
183
explicit location flags if the command requires them.
184
185
* **Location Discovery**: If the correct region, zone, or location for a
186
service is not known, run discovery commands first (remembering to limit
187
results if there are many):
188
189
* **Compute Engine (VMs, Networks)**:
190
191
* `gcloud compute regions list --project=<PROJECT_ID>`
192
* `gcloud compute zones list --project=<PROJECT_ID>`
193
194
* **Other Services (Standard API Style)**: Many GCP services utilize a
195
unified `locations list` command:
196
197
* `gcloud <GROUP> locations list --project=<PROJECT_ID>`
198
* *Examples*: `gcloud artifacts locations list`, `gcloud kms locations
199
list`, `gcloud secrets locations list`.
200
201
## Safety & Guardrails
202
203
> [!CAUTION] **Destructive actions (delete, update, remove) MUST be explicitly
204
> authorized by the user.** Never invoke them autonomously unless explicitly
205
> instructed to do so in the context of a safe, pre-approved workflow.
206
207
### Prohibited Operations (Denylist)
208
209
NEVER execute the following commands autonomously. These require explicit
210
human-in-the-loop authorization:
211
212
* **Any IAM policy, role, or binding modification** (Security): Risk of
213
privilege escalation, administrative lockout, service disruption, or
214
unauthorized data exposure.
215
* **No Proactive API Enabling**: Assume necessary APIs are enabled. To prevent
216
unexpected resource provisioning or billing charges, do not proactively try
217
to enable APIs. User approval is required to enable any API.
218
* **No Proactive `gcloud` CLI Installation** (Host Modification): Never
219
autonomously install the Google Cloud CLI (`gcloud` CLI) or additional
220
`gcloud` CLI components (`gcloud components install`, `gcloud components
221
update`, or system package manager installs of the `gcloud` CLI). If the
222
`gcloud` binary or a required CLI component is missing, you **must** inform
223
the user, ask for explicit user confirmation (e.g., *"I am ready to install
224
the Google Cloud CLI (`gcloud`). Do you want me to proceed?"*), and
225
**strictly stop** to wait for the user's positive affirmation before
226
executing any installation commands.
227
* **`gcloud * delete`** (Destructive): Irreversible resource destruction
228
(e.g., project deletion) or data wiping.
229
* **`gcloud billing *`** (Financial): Risk of service disruption or unbounded
230
costs.
231
* **`gcloud organizations *`** (Governance): Org-level changes affect security
232
posture for all users.
233
* **`gcloud kms *`** (Encryption): Risk of permanently locking data.
234
* **`gcloud infra-manager deployments apply`** (Destructive): Autonomous IaC
235
execution can destroy managed resources.
236
237
### Execution Guidelines
238
239
* **Dry Run (Mandatory)**: If the `--dry-run` or `--validate-only` flag (or
240
equivalent) is listed in the command help output, ALWAYS include the flag in
241
the proposed command or initial execution step. ALWAYS preview changes with
242
`--dry-run` or `--validate-only` prior to actual execution.
243
244
* **Long Running Operations**: For commands that support it, the `--async`
245
flag is highly recommended for long-running operations to avoid blocking the
246
agentic flow. Note that not every command has an `--async` flag. For
247
commands that return an operation ID (whether via `--async` or by default),
248
operation status must be polled for completion, if needed for the next step.
249
250
* **Non-Interactive Flag (`--quiet`)**: Include `--quiet` (or `-q`) on all
251
proposed or executed commands to guarantee non-interactive execution without
252
waiting for TTY confirmation prompts.
253
254
## Structured Workflows
255
256
### Discovery Workflow
257
258
When asked to perform a task on a service that is unfamiliar:
259
260
1. **Invoke Help**: Call `gcloud help <COMMAND>` on the target leaf command
261
prior to execution.
262
2. **Traverse Command Tree**: Run help on command groups (e.g., `gcloud help
263
compute` or `gcloud help`) to discover available subgroups and commands if
264
the exact command is unknown.
265
3. **Discover Schema**: Run `gcloud <GROUP> <RESOURCE> list --limit=1
266
--format=json` to inspect JSON keys before constructing filters or
267
projections. DO NOT execute unconstrained `list` commands without scoping
268
flags (e.g., `--limit=1`) to prevent context window exhaustion.
269
4. **Enforce Data Reduction**: Include data reduction flags (`--limit`,
270
`--filter`, `--format`) on all command executions.
271
272
## Quick Reference / Cheat Sheet
273
274
Task | Command Template
275
------------------ | ----------------------------------------------------------
276
Discover Schema | `gcloud <GROUP> <RESOURCE> list --limit=1 --format=json`
277
Filtered List | `gcloud <GROUP> <RESOURCE> list --filter="status:RUNNING"`
278
Specific Columns | `gcloud <GROUP> <RESOURCE> list --format="json(name, id)"`
279
Learn Filters | `gcloud topic filters`
280
Learn Formats | `gcloud topic formats`
281
Learn Projections | `gcloud topic projections`
282
Asynchronous Op | `gcloud <COMMAND> --async`
283
Check Operation | `gcloud <GROUP> operations describe <OPERATION_ID>`
284
Common commands | `gcloud cheat-sheet`
285
List Regions (GCE) | `gcloud compute regions list --project=<PROJECT_ID>`
286
List Zones (GCE) | `gcloud compute zones list --project=<PROJECT_ID>`
287
List Locations | `gcloud <GROUP> locations list --project=<PROJECT_ID>`
288
289
Refer to the
290
[gcloud CLI Scripting Guide](https://docs.cloud.google.com/sdk/docs/scripting-gcloud.md.txt)
291
for guidance on using the gcloud CLI in automation.
292
293
## Reference Directory
294
295
- [CLI Usage](references/cli-usage.md): Platform installation, authentication
296
methods (interactive, headless, ADC, service account keys, impersonation),
297
and local configuration management.
298
299
- [MCP Usage](references/mcp-usage.md): Using the Cloud CLI remote MCP
300
server (`run_gcloud_command`), project parameter scoping, input files, and
301
execution guidelines.
302
303
- [Usage Attribution](references/attribution.md): Standardized usage
304
attribution tags and multi-skill precedence rules for `gcloud` CLI, REST
305
API, and MCP requests.
306

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…