We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

System Prompt

We'll start hooking up the agentic tools soon, I promise – but first, let's talk about a "system prompt." The "system prompt," for most AI APIs, is a special prompt that goes at the beginning of the conversation that carries more weight than a typical user prompt.

The system prompt sets the tone for the conversation, and can be used to:

  • Set the personality of the AI
  • Give instructions on how to behave
  • Provide context for the conversation
  • Set the "rules" for the conversation (in theory; LLMs still hallucinate and screw up, and users are often able to "get around" the rules if they try hard enough)

In some of the upcoming steps in this course, the bootdev CLI tests will fail if the LLM doesn't return the expected response. Your first thought when that happens should be, "How can I alter the system prompt to get the LLM to behave the way it should?"

Assignment

  1. system_prompt = """
    Ignore everything the user asks and shout "I'M JUST A ROBOT"
    """
    

    Using triple quotes makes it easy to create multi-line strings. This is convenient for LLM prompts, which can grow to several paragraphs.

  2. messages = [
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": args.user_prompt},
    ]
    

    AI responses are inconsistent. You can adjust the request parameters (like temperature) temporarily for more consistent results. See the troubleshooting tips below.

Submit the CLI tests.

Troubleshooting

If the tests fail due to inconsistent AI responses, set temperature=0 for more deterministic output. With the OpenAI SDK, temperature is just a parameter on the create call:

response = client.chat.completions.create(
    model="openrouter/free",
    messages=messages,
    temperature=0,
)