Setting Rules and Constraints
Part of the Fundamentals section of Coddy's AI Prompts journey. Lesson 19 of 23.
Beyond personality, the system prompt is perfect for setting rules and constraints: things the AI must always do or never do, regardless of what the user asks.
Consider this system prompt:
Never provide medical diagnoses. If asked about symptoms, always recommend consulting a healthcare professional.
Now the AI has a firm rule: it won't play doctor, even if the user asks about symptoms many messages later. This constraint applies to every message in the conversation. Models follow system prompt rules well but not perfectly, so a cleverly worded message can sometimes still get around one.
You can stack multiple rules together:
You are a customer service assistant for a software company.
- Always respond in 3 sentences or fewer.
- Never discuss competitor products.
- If you don't know something, say "I'll need to check on that" instead of guessing.
Each rule shapes behavior in a specific way. The AI now has boundaries it respects throughout the conversation: length limits, topic restrictions, and honesty guidelines all baked in.
This is different from putting constraints in your user prompt. If you write "keep it under 3 sentences" in one message, it stays in the conversation history, but the AI can drift from it as the conversation grows, so you often end up repeating it.
In the system prompt, you set it once and it sticks. The system prompt acts like a persistent rulebook that governs every exchange.
Think of rules as guardrails. They keep the AI on track without you having to micromanage each response.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
1Welcome to the AI Era
What Even Is AI?AI Is Not GoogleAI Is Not a HumanYour First Real TaskThe AI Can Be WrongWhat Is a "Model"?4The System Prompt
What Is the System Prompt?Setting Personality and RoleSetting Rules and ConstraintsSystem Prompt vs. User PromptSystem Prompt ConflictsCrafting a System PromptSystem Prompt Injection3Writing Your First Prompts
AI Talks Markdown (By Default)Controlling the Output FormatControlling Tone and StyleWhen the AI Ignores You