Prompt Engineering Best Practices

Chapter 2 · Practice 3 of 4

Label each document with its source and metadata

From Prompt structure and long context

Why it matters

When you pass several documents, the model needs to tell them apart and refer back to them. Anthropic's guide recommends wrapping each one in <document> tags with <source> and <document_content> subtags, plus any other metadata that matters.

Useful metadata to include:

  • a stable id or index, so the model can cite it;
  • the title or file name;
  • the date, when freshness matters;
  • the type, such as policy, email or transcript.

This makes it possible to ask for citations by id and then check them in code, and it helps the model weigh a current policy above an old draft.