Skip to content
IT Vizag
← Python Meets AI

▶ Sign up free for the video, slides & prompts

The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.

Checking…

System prompts and settings

Lesson 4 of 10 · 2 min read

Give your program rules, a tone and a length limit.

🎬 Video version coming soon — read it now

A system prompt sets the rules for your program's AI: who it is, how it should answer, and what it must never do. The user doesn't see it, but it shapes every reply.

Adding a system prompt

🔒 Code example: sign up free (above) to unlock it.

What belongs in a system prompt

  • Role: "You are a support assistant for a bike rental shop in Vizag."
  • Audience: beginners, customers or doctors. It changes the vocabulary.
  • Format: bullet points, under 100 words, always end with a question.
  • Boundaries: what to refuse or redirect, such as "If asked about prices, say: please call the shop."
  • Context: facts the model needs, such as opening hours or your course syllabus.

The same prompting skills from the Prompting & ChatGPT course apply. The system prompt is just a briefing written once in code.

Settings in code

  • max_tokens caps the reply length. If a reply stops mid-sentence, check response.stop_reason: "max_tokens" means it hit the cap.
  • Length in the prompt: to get shorter answers, ask for it in the system prompt ("under 80 words"). max_tokens only cuts the reply off; it doesn't make the model plan a shorter answer.
  • model: larger models are better at hard reasoning; smaller ones are faster and cheaper. Compare them on your task before deciding.

Test the rules

🔒 Code example: sign up free (above) to unlock it.

(Here ask_with_system is your ask function from the last lesson, updated to pass system=SYSTEM.)

Check that each answer follows every rule. If one doesn't, make that rule clearer. This simple habit is the start of what professionals call evaluation.

Tip: Keep the system prompt in a constant or a separate text file. You'll edit it far more often than the code around it.

In one line

The system prompt sets your AI's role, format and limits; test it with tricky inputs and refine the wording until every rule holds.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend