User Messages are the human-turn inputs in a chat API conversation that represent the actual queries, instructions, and content a user or application sends to the language model — the primary mechanism through which developers and end users communicate intent, provide context, and drive model behavior within the boundaries established by the system prompt.
What Is a User Message?
- Definition: Messages with the "user" role in a chat completion API call — representing human inputs in the conversation turn structure that alternates between "user" and "assistant" turns.
- Position in the Stack: One of three primary message roles in the OpenAI Chat Completion format: system (configuration), user (human input), assistant (model output).
- Content Flexibility: User messages can contain plain text, structured data, code, images (multimodal models), file contents, few-shot examples, or any combination — the content field is a rich text or multimodal payload.
- API Structure:
{"role": "user", "content": "What are the key differences between REST and GraphQL?"}
Why User Message Design Matters
- Model Behavior Driver: After the system prompt sets the context, user message content is the primary driver of what the model produces — poor user message structure yields poor responses even from capable models.
- Prompt Engineering Surface: The user message is where most prompt engineering techniques are applied — chain-of-thought instructions, few-shot examples, structured data injection, and output format specifications.
- Context Carrying: In multi-turn conversations, user messages carry the conversation history — each API call includes all prior user and assistant messages, giving the model full context.
- Programmatic Injection: In agentic systems, user messages are often programmatically generated — assembling retrieved context, tool outputs, and structured data before sending to the model.
User Message Content Patterns
Simple Query: "Explain how transformer attention works in simple terms."
Structured Data Input: "Analyze this customer feedback and categorize each as Positive/Negative/Neutral: 1. 'The product arrived damaged' 2. 'Fast delivery, exactly what I ordered' 3. 'Average quality for the price'"
Few-Shot Examples in User Message: "Classify the sentiment of these reviews. Examples: Input: 'Loved it!' → Output: Positive Input: 'Terrible quality' → Output: Negative Now classify: 'It was okay, not great but not bad'"
Large Document Processing: "Here is a 50-page legal contract: [FULL TEXT]. Summarize the key obligations of each party, highlight unusual clauses, and flag any indemnification language."
Code Review Request: "Review this Python function for performance issues, security vulnerabilities, and adherence to PEP 8: [CODE BLOCK]"
Advanced Technique: Prefill via User Message
In some model APIs (especially Anthropic), you can "prefill" the assistant turn by adding an assistant message that the model must continue from — effectively constraining the start of the response:
[
{"role": "user", "content": "Write a Python function to parse JSON."},
{"role": "assistant", "content": "```python
def parse_json("}
]
This forces the model to immediately produce code without preamble ("Sure! Here is the code..."), reducing tokens and latency.
User Message Best Practices
- Specificity: "Write a function to sort a list of dictionaries by the 'age' key in descending order" produces better code than "Write a sort function."
- Context First: Provide context before the instruction — "I'm building a REST API with FastAPI for a healthcare application. How should I handle authentication?"
- Output Format Specification: Explicitly state desired format — "Return your answer as a JSON object with keys: summary, key_points (list), confidence (0-1)."
- Constraint Specification: State limitations — "Answer in 3 sentences or fewer. Use only information from the provided document."
- Step-by-Step Triggering: Add "Think step by step" or "Let's reason through this carefully" to trigger chain-of-thought reasoning for complex problems.
User Message in Agentic Pipelines
In autonomous agent systems, user messages are often programmatically assembled:
1. Retrieve relevant context from vector database. 2. Format tool output results from previous agent steps. 3. Inject current date, user account state, available actions. 4. Construct the user message combining retrieved context + task instruction. 5. Send assembled message to the model.
User messages are the programmable input surface where prompt engineering skill translates directly into model output quality — understanding how to structure user messages with appropriate context, constraints, examples, and format instructions is the highest-leverage skill for developers building AI-powered applications.
Explore 500+ Semiconductor & AI Topics
From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.