Generative AIby Dhruv Narang

1. The Four Roles

Every message has a role, because the provider's API must know who is speaking. LangChain writes a role in two ways: a short tuple like ("system", "..."), or a message class like SystemMessage.

RoleWhat it isAs a tupleAs a class
systemThe rules, written by the developer("system", "...")SystemMessage
humanThe user's question("human", "...")HumanMessage
aiThe reply from the model("ai", "...")AIMessage
toolThe result of a tool. We use it later, when the model calls tools("tool", "...")ToolMessage

2. Three Ways to Send a Prompt

In LangChain you send a prompt with model.invoke(). You can pass a plain string, a list of tuples, or a list of message classes. Same idea, three ways to write it.

response = model.invoke("What is a Python list?")
print(response.content)messages = [
    ("system", "Answer in one line."),
    ("human", "What is a Python list?"),
]
response = model.invoke(messages)
print(response.content)from langchain_core.messages import SystemMessage, HumanMessage

messages = [
    SystemMessage(content="Answer in one line."),
    HumanMessage(content="What is a Python list?"),
]
response = model.invoke(messages)
print(response.content)
A plain string. LangChain sends it as one Human message.A list of (role, text) tuples. The short way to write System and Human messages.The same list, written with the message classes from LangChain.

3. Same Question, New Personality

The question stays the same. Only the system prompt changes, and the model changes how it talks. Pick a personality.

messages = [
    ("system", "Answer in one word."),
    ("human", "What is the capital of Rajasthan?"),
]
response = model.invoke(messages)
print(response.content)messages = [
    ("system", "You are a friendly teacher. Explain in 2 lines."),
    ("human", "What is the capital of Rajasthan?"),
]
response = model.invoke(messages)
print(response.content)messages = [
    ("system", "Talk like Amitabh Bachchan: a deep, dramatic voice with pauses. Keep it to 2 lines."),
    ("human", "What is the capital of Rajasthan?"),
]
response = model.invoke(messages)
print(response.content)messages = [
    ("system", "Talk like Samay Raina: sarcastic, self-roasting humour. Keep it to 2 lines."),
    ("human", "What is the capital of Rajasthan?"),
]
response = model.invoke(messages)
print(response.content)
AI message
JaipurJaipur is the capital of Rajasthan.
It's known for its vibrant culture, historic palaces, and bustling markets.
In the heart of the Rajput kingdom… the capital rises, a city of forts and history.
Jaipur, the Pink City, reigns as Rajasthan's capital.
I'm not a geography teacher, but the capital of Rajasthan is Jaipur—so if you're hoping to get lost in a desert, you've come to the right place.
(I'd say I'd be the capital of confusion, but that's just my sense of direction.)
Only the system line changes. These are real answers from a model (gpt-oss-20b on Groq). Your answers will be a little different each time.

4. Common Role Mistakes

A wrong role fails inside LangChain, before anything is sent to the model. LangChain tells you which role it did not understand.

✕ Wrong: capital letters
("AI", "Hello!")
ValueError: Unexpected message type: 'AI'

Fix: write the role in lowercase, "ai".

✕ Wrong: an invented role
("robot", "Hello!")
ValueError: Unexpected message type: 'robot'

Fix: use one of the allowed roles below.

✓ Right
("ai", "Hello!")
No error

The role is lowercase and it is an allowed role.

Allowed roleshumanuseraiassistantsystemtool