QA
Beginner LevelAI, LLMs, Embeddings & MCP

What is the difference between System Prompts and User Prompts in LLM API calls?

❓ Interview Prompt: Explain message role hierarchies (system, user, assistant, tool) in chat completion APIs.

Modern LLM Chat APIs structure interactions using message arrays with explicit roles:

1. System Role (system):

Sets the overarching behavioral persona, constraints, output formatting rules, and safety boundaries. Given higher priority in model instruction following.

2. User Role (user):

Contains the input query, message payload, or question submitted by the end user.

3. Assistant Role (assistant):

Contains previous responses generated by the LLM in a multi-turn conversation.

4. Tool Role (tool):

Contains results returned by external API function executions back to the model.

Code Implementation Example

typescript
const messages = [
  { role: 'system', content: 'You are a concise TypeScript code reviewer. Respond ONLY with code diffs.' },
  { role: 'user', content: 'How do I check if an array is empty in JS?' },
  { role: 'assistant', content: 'arr.length === 0' },
  { role: 'user', content: 'What about null checking?' }
];
💡Multi-turn conversation payload structuring system, user, and assistant roles.
🎯 Interview Key Takeaway

System prompts establish model persona and rules; user prompts supply dynamic runtime queries.

#System Prompts#User Prompts#Chat API#Beginner
Back to all AI, LLMs, Embeddings & MCP Questions→

More AI, LLMs, Embeddings & MCP Interview Questions

Beginner LevelAI, LLMs, Embeddings & MCP

What are Vector Embeddings and Cosine Similarity in AI Semantic Search?

Beginner LevelAI, LLMs, Embeddings & MCP

What is the Model Context Protocol (MCP) and how does it connect LLMs to external tools?

Beginner LevelAI, LLMs, Embeddings & MCP

What is Retrieval-Augmented Generation (RAG) and how does it prevent LLM hallucinations?