Claude With Amazon Bedrock
← All lessons
Lesson 10Claude With Amazon Bedrock

Controlling model output

Summary audio

Spoken summary — press play to read along: the line being spoken stays near the top.

Study notes

Influencing Claude Output: Advanced Techniques

**I. Pre-filling Assistant Messages**

  • Purpose: To strongly steer or direct Claude's response toward a specific viewpoint or direction.
  • Method: Manually include an "assistant message" within the message list you send to the model.
  • Mechanism: Claude interprets this pre-filled message as content that has already been authored. It uses this text as a starting point and continues generating its response from the very end of the pre-filled text.
  • Key Consideration: The pre-filled text is generally not a complete sentence. The user must manually combine (stitch) the pre-filled text with the partial response generated by Claude to form a coherent final output.

**II. Stop Sequences**

  • Purpose: To force Claude to terminate response generation immediately upon encountering a specific string.
  • Method: Provide one or more specific strings (stop sequences) as an optional parameter in the function call (e. g. , stop_sequences).
  • Mechanism: When Claude generates any of the specified sequences, the generation process halts instantly, and the output generated up to that point is returned.
  • Application: Stop sequences can be individual characters or full words, allowing for precise truncation of the model's output.

Takeaways

  • Pre-filling Assistant Messages steers Claude by providing pre-authored text that the model continues generating from.
  • The pre-filled text often requires manual stitching to ensure the final output is coherent.
  • Stop Sequences force Claude to terminate response generation immediately upon encountering a specific string.
  • Stop sequences allow for precise output truncation, ranging from single characters to full words.
Flashcards 7 cards
Question
click to reveal · ←/→
Answer
click to flip back
Export to Anki (.tsv) ↓
Knowledge check 6 questions