0
0
Prompt Engineering / GenAIml~10 mins

Output guardrails in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a maximum length for the generated text.

Prompt Engineering / GenAI
output = model.generate(input_text, max_length=[1])
Drag options to blanks, or click blank then click option'
Atemperature
Bmax_tokens
C50
Dstop_sequence
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameters that control randomness instead of length.
2fill in blank
medium

Complete the code to stop generation when a specific word appears.

Prompt Engineering / GenAI
output = model.generate(input_text, stop=[1])
Drag options to blanks, or click blank then click option'
A'end'
B100
CTrue
Dtemperature
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers or booleans instead of strings for stop.
3fill in blank
hard

Fix the error in the code to prevent generating harmful content by setting a safety filter.

Prompt Engineering / GenAI
output = model.generate(input_text, [1]=True)
Drag options to blanks, or click blank then click option'
Astop
Bmax_length
Ctemperature
Denable_safety_filter
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing safety filter with output length or randomness controls.
4fill in blank
hard

Fill both blanks to set temperature and top_p for safer, more focused output.

Prompt Engineering / GenAI
output = model.generate(input_text, temperature=[1], top_p=[2])
Drag options to blanks, or click blank then click option'
A0.2
B0.9
C0.8
D1.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using high temperature or top_p values that increase randomness.
5fill in blank
hard

Fill all three blanks to add output guardrails: max tokens, stop sequence, and safety filter.

Prompt Engineering / GenAI
output = model.generate(input_text, max_tokens=[1], stop=[2], [3]=True)
Drag options to blanks, or click blank then click option'
A'\n'
Benable_safety_filter
C100
Dtemperature
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up parameter names or using wrong types for stop.