首页 / 文章 / Prompt Engineering for DevOps: The C.L.E.A.R. Checklist and a Prompt Library

本文以英文发布。

Prompt Engineering for DevOps: The C.L.E.A.R. Checklist and a Prompt Library

Practical prompt engineering for DevOps: a five-part checklist, before and after examples for Terraform, Kubernetes and CI, plus tips for building a reusable prompt library.

1153 词

Prompt engineering sounds like a buzzword until the first time a sloppy question costs an hour. When AI is part of daily infrastructure work, a vague prompt gets a vague answer back. Sometimes it's a wrong answer, and in DevOps wrong can mean a broken pipeline or a destructive kubectl command.

The fix is to treat prompts like code. Version them, test them and reuse them. Here's how that plays out with examples taken from everyday ops work.

Why this matters for ops people

Nobody's asking the model for poetry. The typical requests look like this:

  • figure out why a Terraform plan fails
  • produce a bash script that won't wipe production
  • shrink 10,000 lines of logs into ten bullets
  • decode a cryptic Kubernetes error message
  • generate YAML that passes validation

"Garbage in, garbage out" applies to prompts just as it does to data. Writing a good one is now as basic a skill as knowing grep or awk.

The mistake almost everyone makes

The usual prompt is something like "Fix my Terraform error". Then the answer comes back generic and useless, which shouldn't surprise anyone, because the model doesn't know:

  • which cloud provider is involved (AWS, GCP or Azure)
  • what the error message actually says
  • which Terraform version is running
  • what has already been tried

Without context there's no useful answer. It really is that simple.

A checklist that fits in your head: C.L.E.A.R.

Five items cover almost every good prompt.

C is for Context. State the environment, for instance a production EKS cluster on AWS.

L is for Limitations. Name the constraints, such as a stateful pod that can't be restarted.

E is for Expected output. Say what shape the answer should take, like a one-line fix instead of a full rewrite.

A is for Actual error or data. Paste the real log or error text.

R is for Role. Ask the model to answer as a senior SRE doing a review.

Each of the five deserves a closer look.

1. Context

Weak version: "Why is my pod crashing?"

Stronger version: a Node.js pod on GKE ran fine for three months and began crash-looping right after a ConfigMap change the day before.

Now the model knows the platform, the kind of application and the probable trigger. The quality gap between those two prompts is huge.

2. Limitations

A model can't guess your constraints. You have to spell them out, for example: suggest a fix, but the primary database node can't be restarted during business hours.

Leave that out and a casual "just restart it" is likely to show up in the answer. In production, that's anything but casual.

3. Expected output

Name the format you want. This single habit cuts a lot of back-and-forth. Some useful format requests:

  • only the bash command, no commentary
  • reply as a table
  • the YAML block and nothing else
  • the short version, written for someone debugging at 2 AM

4. Actual error or data

People skip this one most often. Paste the real thing.

Weak version: "My CI pipeline is failing."

Strong version: the exact failure output from the job.

Exit code 137 usually means the process was killed for running out of memory. The model can only spot that if the real error is in front of it.

5. Role

A role shifts both the tone and the depth of the reply. Compare asking for an answer from a senior SRE with ten years of Kubernetes experience against asking for an explanation aimed at a beginner. The question stays the same, yet the answers differ a lot, and both can be exactly what's needed on a given day.

Prompts that earn a place in the snippets file

Some prompts are worth saving once they work.

Terraform debugging. Ask for the role of a senior DevOps engineer, paste the plan error, give the provider (AWS) and the Terraform version (1.7), and request the root cause in one line followed by the fix.

Safe automation scripts. Ask for a bash script that removes Docker images older than seven days. Require a dry-run mode as the default, and forbid deleting anything without confirmation.

Log summaries. Hand over the Nginx logs and ask for the five most common error codes, the busiest endpoints and any suspicious IP patterns, all in under 100 words.

Incident postmortems. Supply raw incident notes and ask for a clean document with Summary, Timeline, Root Cause and Action Items sections.

Habits that backfire

Several patterns keep producing bad results:

  • stuffing five unrelated problems into a single question
  • leaving out the tech stack, even though Terraform, CloudFormation and Pulumi give very different answers
  • taking the first reply at face value instead of asking "why" at least once
  • forgetting to mention that the environment is production when it is
  • pasting model output straight into production unreviewed

That last habit deserves a warning label of its own. The AI is a co-pilot, and a person remains the pilot.

Keeping a prompt library

Teams already keep script libraries and runbooks, and a prompt library fits right next to them. A simple layout:

/prompts
  ├── terraform-debug.md
  ├── log-summary.md
  ├── incident-postmortem.md
  ├── yaml-validator.md
  └── cost-report-summary.md

Each file holds the reusable template, placeholder fields such as [ERROR], [STACK] and [ENV], and a brief note on when to use it. That moves prompt writing from typing at random to choosing the right tool, the same as picking the right script from a folder.

Weak versus strong, side by side

CI failure

  • Weak: "CI is broken, help"
  • Strong: "GitHub Actions fails at the docker build step with exit code 137, probably out of memory. Suggest a memory fix for the runner."

Kubernetes problem

  • Weak: "Pod keeps crashing"
  • Strong: "Node.js pod on GKE has been crash-looping since yesterday's ConfigMap change. Logs show OOMKilled. Suggest a resource limit fix."

Script request

  • Weak: "Write a cleanup script"
  • Strong: "Write a bash script that deletes Docker images older than seven days, includes a dry-run flag and never deletes automatically."

Where to start

Prompt engineering isn't magic. It's the same precision that goes into a good ticket or a clear runbook. Start small, save the prompts that work, and reuse them. Handle them like code, because at this point they pretty much are.