Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT SWIFT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST

AWS Amazon Anthropic Claude


Anthropic Claude

Anthropic Claude is a large language model developed by Anthropic.

Review the following best practices for using Anthropic Claude.


Add tags in the prompts

Prompts sent to Claude models must contain \n\nHuman: and \n\nAssistant: as the signals that indicate who is speaking.

Adding human and assistant tags in the prompts guides Anthropic models to generate desired outputs. Also, you can include an optional \n\nAssistant: preamble to the response.

Why do we need those tags in API?
Claude has been trained and fine-tuned using RLHF (reinforcement learning with human feedback) methods on \n\nHuman: and \n\nAssistant: data like this, so you will need to use these prompts in the API in order to stay “on-distribution” and get the expected results.


Include detailed descriptions

Claude responses can be chatty, so it's important to give a detailed task description, including rules and exceptions. Explain it as you would to a new employee with no context. You can include example inputs and outputs to improve formatting and accuracy.

Provide the specific input to process and demonstrate the output formatting you want. You can also deal with Claude’s natural chattiness by asking it to enclose the output in a specific format.


Limit the response by pre-filling

Claude provides verbose responses. To limit the information in each response, you can pre-fill the response yourself. This helps Claude respond more quickly because processing input is less complicated than generating output. Review the following example.

Prompt
Human: Give me five synonyms of the word “dust.” I mean the verb, not the noun.
Assistant: Here are the five synonyms of the verb “dust”: pre-filled the response

Use XML tags

XML tags like <tag>this</tag> can be useful for defining structure in your prompt and also in Claude's response. For example, if you want to reference a long piece of text, such as an article, tell Claude that you wrapped it in tags. This makes it obvious where the article starts and ends.

If your prompt includes a reference to a long piece of text, such as an article, put your instruction after the article rather than before it. Consider the following useful tips:

  • Tip 1: You can ask Claude to use XML tags in the response to make it easy for you to extract key information. You can also end your prompt with the opening XML tag as a good method for skipping the preamble.
  • Tip 2: You can use tags for few-shot learning.

Specify output length

For the best results, specify an approximate number of words, paragraphs, or items in a list. Asking for a specific number of characters is typically less effective.


Set clear expectations

Make sure to set the right expectation with Claude, as the model might give you information that isn't relevant to the question. If Claude provides responses with hallucinations or incorrect information, try to fully explain the task with more clarity. It also helps to anticipate failure in your prompt and explain why a certain response would be a failure.


Break up complex tasks

Divide complex tasks into subtasks, break the prompt into multiple prompts, or ask the model if it understands the instructions. As you learned earlier, asking the model to think step by step can also help you with complex tasks.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.