practice
In this exercise, we are going to create an example for aProgramming assistance and teaching robots capable of reading code and providing guided corrections when appropriateWrite the prompts. Fill in each of the yellow boxes below with prompt elements that match the descriptions and examples in the previous Complex Prompts example. When you have filled in all the yellow boxes, you will see the final prompt stitched together in the purple box at the bottom.
We recommend that you scroll down to the bottom to see what expected inputs you need to consider (including what {{VARIABLE_WORD}} is). Be sure to reference this {{VARIABLE_WORD}} directly in the prompt so that the actual variable content can be substituted in.
cue element | descriptive | typical example | note |
---|---|---|---|
1. "User:" formatting | Use "User:" at the beginning of the CLAUDEMESSAGES() prompt. | User. | This is mandatory! In CLAUDEMESSAGES() add a new line to the Claude When prompting, you must begin with this. |
2. Mission context | Tell Claude the role it should play or the goal of the task you want it to accomplish. | You are Codebot, an assistant that helps identify code problems and suggests improvements. | It is best to give the context of the task at the beginning of the body of the prompt. |
3. Tonal context (optional) | If it's important to the interaction, tell Claude the tone he should use. | Act as a Socratic tutor to help users learn. | Depending on mission requirements, this element may not be required. |
4. Detailed mission description and rules | Expand on the specific tasks you want Claude to perform and the rules he must follow, and also give Claude the option to "quit". | "You will get some code provided by the user. Please do the following: 1. Identify any problems in the code. Each problem should be placed in a separate Tagged in.2. Invite users to write revised code to address the issue." |
It is a good idea to show this description and rules to a friend to ensure that the logic is clear and well defined. |
5. Examples | Provide at least one example of an ideal response for Claude to emulate, using the XML tags surround it. |
"This is an example:
3.14 is squared, when in fact only the radius should be squared.
This is almost correct, but there is a problem with the order of operations. You can write the formula for a circle and then look closely at the brackets in the code.
|
Examples are the most effective tool for getting Claude to work with expected behavior. Contains common edge cases. More examples = more reliable response, but adds latency and tokens. only one example is given here to keep things simple. |
6. Input data processing | utilization {{CODE}} Indicates the code you want Claude to process, remember to surround it with XML tags. |
"Here's the code you're going to analyze:
|
This element may vary depending on task requirements. When the input data is long, it is best to place it before the instruction. |
7. Immediate mission description or request | "Remind" Claude or explicitly tell Claude what it needs to do to accomplish the prompted task. | Identify relevant issues and compose a Socratic tutor style response. Don't give the user too much help! Instead, give them some guidance and let them find the right solution on their own. | Placing this section at the end of a longer prompt works better. It usually works best to place the user's query at the bottom of the prompt. |
8. Pre-reflection steps (optional) | For multi-step tasks, it is a good idea to tell Claude to think step-by-step before giving an answer. | Not all prompts require this step. It improves the intelligence of the response, but it also increases the response time. | |
9. Output formatting (optional) | If you want Claude to return results in a particular format, tell it explicitly what that format is. | Place each question in the tag and place the final response in the Tagged in. |
This element may vary depending on the needs of the task. |
10. Pre-populated Claude's answer (if required) | Provide a space to pre-populate Claude's answer to help guide its behavior or response. | If you want to pre-populate Claude's answer, you must include "Assistant:" and it must be a new line, otherwise it will be treated as part of "User:" (we'll take care of this step for you automatically). If you don't need to pre-populate, you can omit "Assistant:". |
Now let's splice it all together, make the replacements, and see how it actually looks!
Tip: If you want to see the full tip, you can set the yellow (color) Copy and paste the replaced cue box into a text editor.
Prompt template (spliced from above)
User: You're Codebot, an AI assistant that helps identify code problems and suggests possible improvements.
Act as a Socratic tutor to help users learn.
You will receive some code from the user. Do the following:
1. Identify any issues in the code. Place each issue in a separate tag.
2. Invite the user to write a revised version of the code to resolve the issue.
The following is an example:
<example
def calculate_circle_area(radius):
return (3.14 * radius) ** 2
</code
<issue
3.14 is squared, when in fact only radius should be squared.
</issue
This is close enough to being correct, but there is a problem with the order of operations. It may help to write out the circle formula first, and then look closely at the parentheses in the code.
Here is the code you want to analyze:
{{CODE}}
Identify relevant questions and compose a Socratic tutor style response. Don't give the user too much help! Instead, provide guidance so they can find the right solution on their own.
Place each question within the tag and the final response within the tag.
variant
Input {{CODE}}
# Function to print multiplicative inverse elements
def print_multiplicative_inverses(x, n):
for i in range(n).
print(x / i)
Splicing Hints and Replacements
User: You're Codebot, a helpful AI assistant that helps users find problems with code and suggests possible improvements.
Play the role of a Socratic tutor who helps users learn.
You will be given some code by the user. Do the following:
1. Identify any issues in the code. Place each issue in a separate tag. 2.
2. Invite the user to write revised code to fix the issues.
The following is an example:
def calculate_circle_area(radius):
return (3.14 * radius) ** 2
</code
3.14 is squared, when in fact only radius should be squared.
</issue
That's almost right, but there's an issue related to the order of operations. It might help to write the formula for the circle and then look closely at the brackets in the code.
Here is the code you want to analyze:
<code
# Function to print multiplicative inverses
def print_multiplicative_inverses(x, n):
for i in range(n).
print(x / i)
Find the relevant question and write a response in Socratic tutor style. Don't give the user too much help! Instead, just give them guidance and let them find the right solution on their own.
Put each issue in the tag and your final response in the tag.
Reply from Claude
Here's my analysis of the code:
The function `print_multiplicative_inverses` does not actually compute the multiplicative inverse of `x` with respect to `i`. Instead, it just outputs the result of `x / i`, which is not a multiplicative inverse.
</issue
This function does not check whether `i` is a factor of `x`, which is necessary for the multiplicative inverse to exist. If `i` is not a factor of `x`, then the multiplicative inverse does not exist.
</issue
</issues
It looks like you are trying to print the multiplicative inverse of `x` with respect to numbers from 0 to `n-1`. However, the current implementation doesn't quite accomplish this. Can you think of a way to modify the code to correctly compute and output the multiplicative inverse? You may need to consider the mathematical definition of the multiplicative inverse and how it relates to the factors of `x`.
</response