aiwithgrant
about me
aiwithgrant›Guides›Anthropic
Anthropic
Anthropic
Official Docs
Intermediate

Long Context Prompting Tips

Techniques for leveraging Claude's 200K token context window with large documents and data.

Official Anthropic docs →
Content sourced from official Anthropic documentation
1

Put longform data at the top

Place your long documents and inputs (20K+ tokens) near the top of your prompt, above your query, instructions, and examples.

šŸ’”Queries at the end can improve response quality by up to 30% in tests, especially with complex, multi-document inputs.
2

Structure documents with XML tags

When using multiple documents, wrap each in <document> tags with metadata subtags. This prevents Claude from confusing which content came from which source.

Multi-document structure
<documents>
  <document index="1">
    <source>annual_report_2023.pdf</source>
    <document_content>
      {{ANNUAL_REPORT}}
    </document_content>
  </document>
  <document index="2">
    <source>competitor_analysis_q2.xlsx</source>
    <document_content>
      {{COMPETITOR_ANALYSIS}}
    </document_content>
  </document>
</documents>

Analyze the annual report and competitor analysis. Identify strategic advantages and recommend Q3 focus areas.
Number documents with index attributes, reference by index or source name in your query, and ask Claude to cite which document its info comes from.
3

Ground responses in quotes

For long document tasks, ask Claude to quote relevant parts first before carrying out its task. This helps Claude cut through the noise.

Medical diagnosis with quotes
You are an AI physician's assistant. Your task is to help doctors diagnose possible patient illnesses.

<documents>
  <document index="1">
    <source>patient_symptoms.txt</source>
    <document_content>{{PATIENT_SYMPTOMS}}</document_content>
  </document>
  <document index="2">
    <source>patient_records.txt</source>
    <document_content>{{PATIENT_RECORDS}}</document_content>
  </document>
</documents>

Find quotes from the patient records that are relevant to diagnosing the reported symptoms. Place these in <quotes> tags. Then, based on these quotes, list all diagnostic information in <info> tags.
Quoting first forces Claude to find evidence before reasoning, dramatically reducing hallucination in long-context scenarios.

Key topics covered

Long context
Document structure
XML tags
Quote extraction
Multi-document
Performance optimization
Read the full guide
View the complete Anthropic documentation
Official docs →

More guides