logo
64

Prompt Engineering

⏱️ 30 min

Prompt Engineering: Get Stable Output from Models

What you're probably confused about right now

"I wrote a really long prompt. Why are the results still inconsistent?"

Length doesn't equal quality. Structure and verifiability -- that's what matters.

One-line definition

Prompt Engineering is breaking a task into a structured instruction with role/task/context/constraints/output.

Real-life analogy

Give an intern a clear template and rubric, and the results will be way more consistent than "just wing it."

Minimal working example

Role: Python engineer
Task: Clean an email list
Constraints: Deduplicate, preserve order, return invalid items separately
Output: JSON(valid, invalid, count)

Quick quiz (5 min)

  1. Rewrite a weak prompt into a structured prompt.
  2. Add edge case constraints.
  3. Define a fixed output schema.

Quiz answer guide & grading criteria

  • Answer direction: write runnable code that covers the core requirements and edge cases from the prompt.
  • Criterion 1 (Correctness): Main flow produces correct results, key branches execute.
  • Criterion 2 (Readability): Clear variable names, no excessive nesting.
  • Criterion 3 (Robustness): Basic protection against null values, type errors, or unexpected input.

Take-home task

Design a prompt for "order number extraction + masking" and iterate through 2 rounds.

Acceptance criteria

You can independently:

  • Write structured prompts
  • Constrain output format
  • Improve stability through iteration

Common errors & debugging steps (beginner edition)

  • Can't read the error: start from the last line -- find the error type (TypeError, NameError, etc.), then trace back to the line in your code.
  • Not sure about a variable's value: throw in a temporary print(var, type(var)) at key points to verify data looks right.
  • Changed code but nothing happened: make sure the file is saved, you're running the right file, and your terminal is in the correct venv.

Common misconceptions

  • Misconception: longer prompts are better.
  • Reality: clear structure and testability beat length every time.