If you want to classify an input, or have Claude respond in one of a few ways that you extract for use in your system, you can use XML tags.
Claude is a conversational agent, so often it will explain at length why it selected a given option. You can ask Claude to highlight just its choice. Afterwards, you can write some text manipulation code to extract the choice.
For example, you can instruct Claude (like you would when training a contractor) to put its final selection between tags, like <result>MY CHOICE HERE</result>. Then you can write a little bit of code to separate out Claude’s choice and discard any other text.
Future development
We will probably offer a simpler “multiple choice endpoint” in the future. Once we do this, you will not have to add any of your own text stripping code to get reliable multiple-choice behavior.
Examples
Human: Here is an email to a customer service address. Please categorize it as low, medium, or high priority between <priority></priority> tags — e.g. "This email is <priority>low</priority> priority" — and explain why.
Email:
<email>
Does Lensly contacts sell Lensly branded astigmatism lenses?
</email>
Assistant:
If you just want a fast multiple-choice answer and no explanation, you can use the "Human:"/"Assistant:" formatting in the API to put words in Claude's mouth. That way you can immediately get a response in the first token. For exmaple:
Human: Here's an email from a customer:
<email>
I don't recognize this charge on my credit card, please help!
</email>
You must help us classify this email into one of the following categories:
- technical issue
- billing inquiry
- account change
- product question
- return or refund
- other
Please put the result into <category> XML tags.
Assistant: This email is in the category <category>billing inquiry</category>.
Human: Very good. Here is another email to classify:
<email>{{NEW_EMAIL}}</email>
Assistant: This email is in the category <category>
Human: I want you to help me find the least healthy food item from a list. By "least healthy" I mean the item that has features like being heavily processed, low in vitamins and minerals, and high in sugar or saturated fat. So I might give you a list of food items like this:
- Carrots
- Peas
- Chocolate
And I want you to identify the least healthy item and put it in double square brackets like [[this]]. You don't need to write out anything except the least healthy item. So if I gave you the list above then you would just response [[Chocolate]]. Do you understand?
Assistant: I understand. To find the least healthy item from a list that you provide, I will look for the item that is most heavily processed, lowest in vitamins and minerals, and highest in sugar or saturated fat. I will then put double square brackets around that item in my response. For example, given the list you provided of carrots, peas, and chocolate, I would respond:
[[Chocolate]]
Human: That's right! Now here is the list of foot items:
{{EXAMPLE_LIST}}
Please identify the least healthy item on this list and put it inside double square brackets like [[this]].
Assistant: