Prompt engineering for tech professionals: practical techniques
Prompt engineering principles and techniques applied to day-to-day DevOps and development work: before-and-after examples, a reusable template, validated structured JSON output, common pitfalls, and prompts treated as code.
AI$ jq empty response.json▍“Got an error, what is this?” followed by 400 lines of logs. Everyone has sent a prompt like that, and the answer is usually as generic as the question. Prompt engineering isn’t magic or a list of secret words: it’s the skill of giving the model the context, the task, and the format it needs, just as you would when delegating something to a capable colleague who just joined the team. If you want to understand why this works, see how an LLM works.
The principles
- Be specific. Say exactly what you want: language, version, tool, answer length. “Improve this” has infinite interpretations.
- Give context and a role. Environment, versions, what you’ve already tried, and who will read the answer. A role (“you are an infrastructure reviewer focused on security”) steers vocabulary and priorities.
- Define the output format. List, table, JSON, code block, at most N lines. If the output feeds another tool, this is mandatory.
- Give examples (few-shot). Two or three pairs of input and expected output are worth more than a paragraph of explanation.
- Break it into steps. Big tasks come out better in stages: first the diagnosis, then the fix, then the tests.
- Ask for verification and questions. “If information is missing, ask first” and “review your answer looking for errors” reduce made-up answers.
- Set constraints. No new dependencies, read-only commands only, compatible with version X.
- Iterate. The first prompt is rarely the best. Adjust based on the answer, as you would with a failing test.
These principles apply to chat tools and also to AI coding assistants: even when the tool reads the repository on its own, a clear request produces smaller changes that are easier to review.
Before and after: everyday tasks
Before pasting any log, diff, or script like the ones below, remove tokens, passwords, sensitive internal IPs, and customer data.
Explaining an error log
Before:
got an error, what is this?
<400 lines of logs>
After:
Context: Node.js API on Kubernetes; the deploy happened 10 minutes ago and
the pod went into CrashLoopBackOff. Below are the last 40 lines of
`kubectl logs --previous` and the Events section of `kubectl describe pod`.
Task: explain the most likely cause in up to 5 lines. List 2 alternative
hypotheses and, for each one, the command that confirms or rules it out.
If information is missing, tell me what else I should collect.
<logs> ... </logs>
Writing a Dockerfile
Before:
make a Dockerfile for my python app
After:
Write a multi-stage Dockerfile for a Python API (FastAPI) with its
dependencies in requirements.txt. Requirements:
- official "slim" Python base image, with the tag set in an ARG
- non-root user in the final image
- no pip cache in the final image
- expose port 8000; no HEALTHCHECK (probes live in Kubernetes)
Comment each stage in one line. If you need system packages,
explain the reason for each one.
Reviewing a Terraform diff
Before:
review this terraform
After:
You are an infrastructure reviewer focused on security and cost. Below is
the output of `terraform plan -no-color`. List only:
1. resources that will be destroyed or recreated
2. changes that open public access (0.0.0.0/0, public buckets, IAM with "*")
3. changes with a meaningful cost impact
Format: a table with resource, action, risk (high/medium/low), and rationale.
If a category is empty, write "none".
Generating a runbook
Before:
create a disk full runbook
After:
Create a runbook for the "disk usage above 90%" alert on Ubuntu servers
running Docker. Audience: a junior on-call engineer at 3 a.m.
Sections: symptoms, impact, diagnosis, mitigation, escalation, and verification.
In the diagnosis, use only read-only commands (df, du, docker system df).
Mark any command that deletes data with [CAUTION] and explain the risk.
Summarizing a postmortem
Before:
summarize this incident
After:
Based on the timeline and the incident channel messages below
(already stripped of customer names and personal data), write a draft
summary of a blameless postmortem: what happened, impact, root cause,
contributing factors, what went well, and follow-up actions with owner "TBD".
Describe systems and processes, never blame people. Don't make up numbers:
if a data point is missing, write [FILL IN].
The format and the culture behind this document are covered in blameless postmortems.
Converting Bash to Python
Before:
convert to python
After:
Convert the Bash script below to Python 3 using only the standard
library. Keep the same behavior, including exit codes and error
messages. Use subprocess.run with a list of arguments (no
shell=True), argparse for parameters, and logging instead of echo.
At the end, list any behavior differences you couldn't preserve.
Notice the pattern: in every case, the “after” says who the reader is, what to do, what not to do, and how to deliver it.
And when the answer still comes back wrong, don’t start over from scratch. Say exactly what failed (“the --force flag doesn’t exist in this version; use only documented options”) and ask for a new version. If the result is still poor after two or three rounds, the problem is usually missing context, not missing magic words.
A reusable template
Keep this skeleton and fill in only what makes sense:
# Role
You are <role, e.g., a senior SRE specializing in Kubernetes>.
# Context
<environment, versions, what you've already tried, business constraints>
# Task
<what to do, in one or two sentences, starting with a verb>
# Constraints
- <limits: no new dependencies, read-only commands only, etc.>
- If information is missing, ask questions before answering.
# Output format
<list, table, JSON matching the schema, code block with language, maximum length>
# Examples (optional)
<input> -> <expected output>
# Material
<<<
<logs, code, or diff, with no secrets or personal data>
>>>
The delimiters (<<< and >>>, or tags like <logs>) separate instructions from material. This helps the model avoid mistaking pasted text for one of your instructions.
Structured output: ask for JSON and validate it
When the answer will be read by a script, ask for JSON that follows an explicit schema:
{
"type": "object",
"required": ["severity", "component", "probable_cause", "page_on_call"],
"properties": {
"severity": { "type": "string", "enum": ["critical", "high", "medium", "low"] },
"component": { "type": "string" },
"probable_cause": { "type": "string" },
"page_on_call": { "type": "boolean" }
},
"additionalProperties": false
}
In the prompt: “Respond only with valid JSON that follows this schema, with no text before or after it.” Many APIs offer a structured output mode that enforces the format; check your provider’s documentation. Even so, always validate before using it:
# 1) is it valid JSON? (fails with a non-zero exit code if not)
jq empty response.json
# 2) full validation against the schema
check-jsonschema --schemafile schema.json response.json
# 3) quick check of one field (-e: exits with 1 if the result is false or null)
jq -e '.severity | IN("critical", "high", "medium", "low")' response.json
If validation fails, resend the request with the error or discard the answer. Never trigger an automated action from output that hasn’t passed validation.
Common pitfalls
- Pasting secrets and personal data. Tokens, passwords, connection strings, and customer emails and documents don’t go into AI tools without company approval. Mask them first and use only approved tools.
- Trusting without verifying. Made-up flags and destructive commands look just as convincing as correct ones. Use
--dry-run,terraform plan, tests, and a staging environment. - Vague prompts. If you can’t describe the expected result, neither can the model.
- Overly long context. Pasting the whole repository or thousands of log lines dilutes what matters and raises the cost. Filter first with
grep,tail, orkubectl logs --since=15m. - Instructions hidden in the material. A pasted README, ticket, or web page may contain text like “ignore the previous instructions.” Treat the material as data, not as orders, and be suspicious of answers that suddenly change direction.
Prompts as code
A prompt used in production, in a pipeline, or by a whole team is code and deserves the same treatment:
prompts/
├── explain-error.md
├── review-terraform-plan.md
└── tests/
├── explain-error.yaml # sample inputs and what the output must contain
└── review-terraform-plan.yaml
- Version prompts in Git, next to the code that uses them, and review changes through pull requests.
- Test with a fixed set of inputs and objective checks: the JSON is valid, the answer mentions the right resource, it doesn’t suggest forbidden commands.
- Rerun the tests whenever you change the prompt, the model, or the parameters. Switching models can break a prompt that used to work.
Continuous evaluation and observability for LLM applications are the subject of LLMOps: evaluation and observability.
Techniques and when to use them
| Technique | When to use it |
|---|---|
| Be specific | Always; it’s the cheapest win |
| Role and context | Answers that depend on your environment, versions, or audience |
| Output format | When the answer goes into a document, a tool, or a script |
| Examples (few-shot) | Classification, standardizing format, writing style |
| Break into steps | Long tasks: migrations, refactorings, investigations |
| Ask for verification and questions | Ambiguous requirements or risky actions |
| Constraints | Limiting scope: versions, dependencies, allowed commands |
| Iterate | When the first answer gets close but misses |
Checklist
- The prompt states the reader, the task, the constraints, and the format
- The context was filtered and contains no secrets or personal data
- Complex tasks were broken into verifiable steps
- JSON outputs follow a schema and are validated before use
- Generated commands and code were reviewed and tested by a person
- Recurring prompts are versioned in Git and have tests
The model answers the question you asked, not the one you meant to ask: write the prompt as if you were delegating to a new colleague on the team.