Generative AI

Day 2: Reshape Your LLM’s Response with a System Prompt

Learn how system prompts shape an LLM’s role, tone, and response format using LangChain, with a complete program and an explanation of every line.

Diagram for Day 2: Reshape Your LLM’s Response with a System Prompt
On this page

This is Day 2 of the Code With Sri 50-Day Gen AI Learning Challenge. In this guide, you will use system instructions to shape an LLM’s role, tone, and response format with Python and LangChain.

We will send the same input to the same model three times and compare how the responses change with different system instructions.

This lesson uses the setup from Day 1 — Your First LLM Call with LangChain.

Understand the basics

A system prompt contains instructions for the model. It can define the role it should take, the task it should perform, the tone it should use, and the format it should follow.

A user prompt supplies the question, request, or data for the current interaction. It can also contain instructions specific to that request.

MessagePurposeLangChain class
System messageSupplies application instructions for how the model should respondSystemMessage
User messageSupplies the current request or inputHumanMessage

On Day 1, we passed a string to model.invoke(). Here, we pass a list of messages so we can include the system instructions alongside the user input.

1. Run the program

For this experiment, the input is a customer complaint about a broken earbud and a delayed support response.

The program first sends that complaint alone. It then adds instructions for a sentiment label, followed by a different set of instructions for a support email.

Open day-02-system-prompts.ipynb using the same VS Code kernel as Day 1. Run the program below in order with Shift + Enter or the cell’s Run button. You can place each model call in its own cell to inspect the output before continuing.

python
customer_complaint = "I bought these wireless headphones last week, Left earbud already stopped working. And support hasn't replied in 3 days"
 
from dotenv import load_dotenv
load_dotenv()
 
from langchain.chat_models import init_chat_model
from langchain.messages import SystemMessage, HumanMessage
 
model = init_chat_model(model='gpt-5-nano')
 
user_message = HumanMessage(content=customer_complaint)
 
plain_response = model.invoke([user_message])
 
print(plain_response.content)
 
sentiment_system_prompt = SystemMessage(content=
                                        """You're a sentiment analyst for product feedback.
                                        Classify the customer's sentiment.
                                        Return exactly one label: Positive, Neutral, or Negative"""
                                        )
 
sentiment_label_response = model.invoke([sentiment_system_prompt, user_message])
 
print(sentiment_label_response.content)
 
reply_system_prompt = SystemMessage(content=
                                    """You write customer support reply emails for an Electronic Store - RadioShack. 
                                    Keep it short, polite, professional and empathetic reply acknowledging the product issue, and if there is any delay in response.  Ask for order number if not mentioned in complaint.
                                    And strictly avoid promising refund or replacement"""
                                    )
 
reply_message_response = model.invoke([reply_system_prompt, user_message])
 
print(reply_message_response.content)

The three calls use the same model and same customer message. Each model.invoke() call sends its own request.

2. Understand every line

Store the input

python
customer_complaint = "I bought these wireless headphones last week, Left earbud already stopped working. And support hasn't replied in 3 days"

The variable customer_complaint stores the text we will send in all three calls. Keeping the input fixed makes it easier to compare the effect of the system instructions.

Load the API key

python
from dotenv import load_dotenv
load_dotenv()

load_dotenv is imported from the python-dotenv package. Calling it loads values from the local .env file. The OpenAI integration uses the OPENAI_API_KEY value when sending requests.

Import the model initializer and message types

python
from langchain.chat_models import init_chat_model
from langchain.messages import SystemMessage, HumanMessage

init_chat_model sets up the model client. SystemMessage and HumanMessage let us identify the role of each message in the input.

Initialize the model

python
model = init_chat_model(model='gpt-5-nano')

We choose GPT-5 Nano and store the client in model. This prepares the client for the calls below.

Create the user message

python
user_message = HumanMessage(content=customer_complaint)

content holds the complaint text. We reuse the resulting user_message object in each request.

Send the input alone

python
plain_response = model.invoke([user_message])
print(plain_response.content)

The square brackets create a list containing the user message. invoke() sends that list to the model and returns its response.

plain_response.content gives us the response content, and print() displays it below the notebook cell.

Here, the model offered troubleshooting advice, next steps, and a draft message the customer could send to support.

Create the sentiment analysis - system prompt

python
sentiment_system_prompt = SystemMessage(content=
                                        """You're a sentiment analyst for product feedback.
                                        Classify the customer's sentiment.
                                        Return exactly one label: Positive, Neutral, or Negative"""
                                        )

This prompt gives the model a role, a task, and a format.

InstructionPurpose
“You're a sentiment analyst for product feedback”Defines the role
“Classify the customer's sentiment”Defines the task
“Return exactly one label”Specifies the answer format

Send the system instructions with the user message

python
sentiment_label_response = model.invoke([sentiment_system_prompt, user_message])
print(sentiment_label_response.content)

The list now contains the system instructions first and the same user message second. The result was:

text
Negative

Create the support team response email - system prompt

python
reply_system_prompt = SystemMessage(content=
                                    """You write customer support reply emails for an Electronic Store - RadioShack. 
                                    Keep it short, polite, professional and empathetic reply acknowledging the product issue, and if there is any delay in response.  Ask for order number if not mentioned in complaint.
                                    And strictly avoid promising refund or replacement"""
                                    )

This time, the model is asked to write a support email for the example store, RadioShack. The prompt specifies a polite, professional, empathetic tone and asks it to acknowledge the issue and delayed response.

It also includes a conditional instruction to request the order number when it is missing, plus a restriction on promising refunds or replacements.

Run the final call and display the reply

python
reply_message_response = model.invoke([reply_system_prompt, user_message])
print(reply_message_response.content)

We swap in the support instructions and reuse user_message. The result is stored in reply_message_response, and its content is printed.

As requested the model acknowledged and asked for further details.

text
Hello,
 
I’m sorry for the delay in getting back to you, and I’m sorry to hear the left earbud isn’t working.
 
Could you please share your RadioShack order number (or any receipt details) and the model/sku of the headphones? This will help us assist you more quickly.
 
If you’d like to try in the meantime:
- Place both earbuds in the charging case and recharge for at least 30 minutes.
- Re-pair the left earbud with your device following the pairing instructions.
- Check for any debris on the earbud contacts and clean gently.
- If your manual includes a reset option, try resetting and then re-pairing.
 
Once we have your order number and model, we’ll review and advise on the next steps.
 
Thank you for your patience, and I apologize again for the delayed response.
 
Best regards,
RadioShack Support

The complete reply also included troubleshooting suggestions and a sign-off. It avoided promising a refund or replacement and requested Order ID.

3. Compare the responses

Input sentObserved response
User message aloneGeneral advice and troubleshooting without any direction
Sentiment system prompt and user messageOne sentiment label
Support system prompt and user messageA support email requesting the order number

Each request uses a fresh message list. The previous response is excluded from the next call, so each run works from the messages supplied to it.

What you learned

  • A system prompt guides the model’s role, task, tone, and response format.
  • HumanMessage represents the current user input.
  • SystemMessage represents the system instructions supplied by the application.
  • model.invoke() sends the message list, and .content gives you the response content.
  • Changing the system instructions can reshape the answer while reusing the same user input.

Try it yourself

Add an order number to the complaint and recreate user_message. Run the support call again and check whether it follows the conditional instruction.

You can also change the requested tone from professional to friendly and conversational, then compare the wording.

Next in the challenge

On Day 3, we will provide a few labeled support tickets and ask the model to classify a new ticket.

Keep learning with Sri

More practical tutorials and experiments on the channel.

Watch on YouTube
Back to articles