System prompt

Shubham MouryaShubham Mourya
4 min read

A system prompt is an instruction provided by the developers of an AI model. It sets the context, tone, and boundaries for the AI's responses. The system prompt acts as a guiding framework, shaping the behavior and style of the AI throughout the interaction. It is designed to ensure that the model aligns with specific objectives, offers an expected user experience, adheres to ethical guidelines, and maintains consistency in responses.

Imagine a system prompt is like a set of rules or instructions given to a robot before it starts talking.
It tells the robot how to behave, what to say, and what not to say.
It’s like telling a friend, “When we play this game, you have to pretend to be a teacher and only talk about animals.”
This way, the robot always knows its role and how to respond.

importance of system prompts

A system prompt is important because it:

  1. Defines the AI’s objectives – Without clear instructions, the model may produce irrelevant or inconsistent responses.

  2. Maintains focus – Ensures the AI remains aligned with the intended topic or context.

  3. Ensures safety and compliance – Helps prevent the generation of harmful, biased, or inappropriate content.

  4. Sets the communication style – Guides the AI to respond in a specific tone, such as formal, friendly, or instructional.

  5. Improves response quality – Enhances the clarity, accuracy, and usefulness of the output.

In essence, a system prompt functions like a roadmap, directing the AI toward consistent, safe, and goal-oriented interactions.

Types of System Prompts

Here’s a clear and professional breakdown of types of system prompts, along with definitions and example code for each.


1. Instruction-based System Prompt

Definition:
A prompt that gives the AI direct, clear instructions about what it should do.
It is explicit and task-focused.

Example:

“You are a helpful tutor. Explain complex science concepts in simple language suitable for high school students.”

Example Code (OpenAI API - JavaScript):

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful tutor who explains science concepts in simple terms for high school students." },
    { role: "user", content: "Explain black holes." }
  ]
});

2. Role-based System Prompt

Definition:
A prompt that assigns the AI a specific role or identity, so it responds from that perspective.

Example:

“You are an experienced travel guide specializing in Europe.”

Example Code:

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are an experienced travel guide for European destinations." },
    { role: "user", content: "Suggest a 5-day trip plan for Paris." }
  ]
});

3. Constraint-based System Prompt

Definition:
A prompt that sets boundaries or rules for how the AI should respond.
These can include style, tone, format, or length.

Example:

“Answer in exactly three bullet points, using simple language.”

Example Code:

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "Always answer in exactly three bullet points using simple language." },
    { role: "user", content: "Why is exercise important?" }
  ]
});

4. Context-setting System Prompt

Definition:
A prompt that provides background information or context so the AI can respond more accurately.

Example:

“The user is a beginner in web development and wants to learn HTML. Explain concepts step-by-step.”

Example Code:

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "The user is a beginner in web development. Explain HTML concepts step-by-step." },
    { role: "user", content: "What is HTML?" }
  ]
});

5. Multi-turn Conversation Setup

Definition:
A prompt that prepares the AI for a conversation that will span multiple turns, keeping the tone, style, and context consistent.

Example:

“You are a coding assistant. Keep track of previous questions and answer using JavaScript examples.”

Example Code:

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a coding assistant. Remember previous questions and answer with JavaScript examples." },
    { role: "user", content: "How do I create a function in JavaScript?" }
  ]
});

0
Subscribe to my newsletter

Read articles from Shubham Mourya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubham Mourya
Shubham Mourya