始める無料で始める

Adding guardrails

One of the most popular uses of system messages is to add guardrails, which places restrictions on model outputs.

In this exercise, you'll place a restriction on model outputs preventing learning plans not related to languages, as your system is beginning to find its niche in that space. You'll design a custom message for users requesting these type of learning plans so they understand this change.

この演習はコースの一部です

Working with DeepSeek in Python

コースを見る

演習の手順

  • Complete the chat request, providing the system message in sys_msg and test a user message containing a non-language-related skill, such as rollerskating.

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")

sys_msg = """You are a study planning assistant that creates plans for learning new skills, returning only the structured plan.

If these skills are non related to languages, return only the message:

'Apologies, to focus on languages, we no longer create learning plans on other topics.'
"""

# Create a request to the chat model
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  messages=[
    {"role": "____", "content": ____},
    {"role": "user", "content": "Help me learn to ____."}
  ]
)

print(response.choices[0].message.content)
コードを編集して実行