Search⌘ K
AI Features

Writing Prompts as Contracts

Understand how to write AI prompts not as open-ended messages but as precise contracts that define tasks, scope, and escalation triggers. This lesson helps you create prompts that produce consistent, structured responses essential for reliable AI feature development.

We’ve now scoped an AI feature end-to-end. This chapter moves to actually building it, and the first skill is writing the prompt itself. If we’ve never called a model API before, this is where that starts. If we have, the more useful shift is treating a prompt as something we design, not something we type into a chat box.

In this lesson, we will cover:

  • What a prompt is, and the two kinds of messages that make one up

  • Why a prompt written like a conversation breaks the code that depends on it

  • What actually belongs in a prompt written as a contract

  • How the support-summarizer’s own prompt, from earlier in this course, is built exactly this way

  • How the same precision shows up in real products

  • The three ways engineers get this wrong

What a prompt actually is

A prompt is the text we send a model; the response is the text it sends back. Here’s the smallest complete version of that exchange, running on Groq’s free API the way every code example in this course does:

Python 3.10.4
from groq import Groq
client = Groq(api_key="{{GROQ_API_KEY}}")
response = client.chat.completions.create(
model="openai/gpt-oss-120b",
messages=[
{"role": "user", "content": "What is 2 + 2?"}
],
)
print(response.choices[0].message.content)
  • Line 1: We import the Groq client. ... ...