AI Engineering
/

Prompting & Structured Output

Prompting & Structured Output

Write clear prompts and validate structured output.

Start topic

Write prompts that state the task, the inputs, and the expected shape of the answer. Validate what comes back and recover when the output does not match the contract.

4 questions

Questions

Easy

Easy
Conceptual

1.5 h

Rewrite a vague request into a testable extraction prompt with category rules, a missing-data policy, consistent examples, and a JSON output contract, then explain why parseable JSON can still be wrong.

Easy
Hands-on

1.5 h

Write a pure function that accepts a model's JSON review summary or returns every contract violation as a stable error code, predict its result for eight replies, and say what a valid summary still cannot prove.

Medium

Medium
Hands-on

3 h

Implement a dependency-free validator for a ticket contract, classify each fixture failure by layer, and design a two-attempt recovery that never commits invalid output.

Hard

Hard
System Design

4 h

Upgrade a ticket classifier to a versioned contract with multiple IDs, evidence, and review states, keep two v1-only consumers working, and decide from evaluation data whether a candidate prompt should ship.

What you will be able to do

  • Write an explicit task instruction with an observable definition of success
  • Keep application instructions separate from untrusted source data, and explain why delimiters alone are not a defense
  • Explain zero-shot and few-shot prompting, and choose examples that cover decision boundaries
  • Give an omitted field, null, and an empty string distinct, documented meanings
  • Distinguish parseable JSON, schema-valid output, and a correct answer
  • Restate an output contract and settle its unclear cases (null versus missing, unknown keys, letter case, whole-number floats) before writing code
  • Check runtime JSON types in JavaScript and Python, including numeric strings, fractions, booleans, null, and arrays
  • Implement a pure validator that returns ordered error codes for every failing field and never throws on bad model output
  • Write table-driven tests for valid, invalid, boundary, and cross-language replies

Before you start

Suggested, not required.

No prerequisites: a good place to start.

Related on CodeSnatch