AI / A CONCEPT NOTE

Prompt Engineering

crafting inputs to get reliable, structured outputs from LLMs

~70 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

The way you phrase a prompt dramatically affects the quality and format of an LLM response. Good prompt engineering uses clear instructions, few-shot examples (showing the model what you want), role-setting ('You are a senior DevOps engineer'), and output formatting (JSON, markdown). Systematic approaches like chain-of-thought improve reasoning tasks.

02 / FOLLOW THE MECHANISM

How a prompt is structured

  1. System message

    sets the model's persona and constraints — e.g., 'You are a Terraform expert. Answer concisely.'

  2. Few-shot examples

    provide 1-3 examples of ideal Q&A pairs to demonstrate format, tone, and depth.

  3. Context injection

    retrieved documents, schema definitions, or API docs are inserted as grounding material.

  4. User query

    the actual question or task, often with explicit instructions like 'respond in JSON with keys: summary, steps, risk.'

  5. Output parsing

    the response is validated against the expected format and error-handled if the LLM deviates.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · INCOMPLETE SKETCH

test prompts via Ollama locally

ollama run llama3 'Write a prompt that...'

The ellipsis omits required code or values. This sketch is not runnable as written.

EXAMPLE 02 · REFERENCE

call OpenAI with a system message

curl -X POST -d '{"model":"gpt-4","messages":[{"role":"system","content":"You are a terse Linux expert"}]}' https://api.openai.com/v1/chat/completions

Explore command anatomy in the CLI lab