# Structured Prompts and Long Context

> Use XML-style tags, clear sections and good document placement so the model never confuses instructions with data. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/structured-prompts
Last updated: 2026-11-28

Use XML-style tags, clear sections and good document placement so the model never confuses instructions with data.

Beginner · about 3 hours · difficulty 2/5

Learn first: [Clear Instructions and System Prompts](https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-fundamentals)

As prompts grow to include documents, examples, tool results and history, **structure** keeps the model oriented and makes your prompts maintainable.

### Techniques

- **Tags as delimiters**: wrap each piece of content, for example `<document>`, `<example>`, `<user_question>`. Claude is notably responsive to XML-style tags, and they help other models too. Refer to the tags by name in instructions ("using only the text in the document tags...").
- **Consistent naming**: pick tag names and stick with them across prompts.
- **Documents first, question last**: for long context, put large documents near the top and the question and instructions at the end.
- **Metadata per document**: include a source, title and date inside each document block so the model can cite.
- **Quote extraction**: for long documents, ask the model to first pull relevant quotes, then answer from the quotes.

### Why this also matters for security

Clear separation between trusted instructions and untrusted data (web pages, emails, user uploads) is the first, though not sufficient, line of defence against **prompt injection**, covered in depth in the safety section. Tell the model that content inside data tags is information, never instructions.

### Good enough to move on

You can build a prompt template that combines multiple documents, examples and a user question with clean tags, and the model answers with correct source references.

## Key concepts

- **XML-style tags as delimiters**
- **Document placement in long context**
- **Per-document metadata**
- **Quote-then-answer**
- **Separating instructions from untrusted data**

## Mini project

Write a prompt template that answers questions over three pasted policy documents using tags, forces the model to quote the relevant passages first, and returns an answer with document references.

## Check yourself

Why does wrapping an uploaded email in tags help, and why is it still not a complete defence against a malicious email?

## Free resources

- [Anthropic docs: use XML tags](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/use-xml-tags) (Anthropic)
- [Anthropic docs: long context tips](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/long-context-tips) (Anthropic)

Previous: [Chain-of-Thought and Task Decomposition](https://www.internhack.in/roadmaps/tracks/ai-engineer/chain-of-thought) · Next: [Prompt Templates, Versioning and Iteration](https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-management)

## More in Prompt Design That Holds Up

- [Clear Instructions and System Prompts](https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-fundamentals)
- [Few-Shot Examples](https://www.internhack.in/roadmaps/tracks/ai-engineer/few-shot-prompting)
- [Chain-of-Thought and Task Decomposition](https://www.internhack.in/roadmaps/tracks/ai-engineer/chain-of-thought)
- [Structured Prompts and Long Context](https://www.internhack.in/roadmaps/tracks/ai-engineer/structured-prompts)
- [Prompt Templates, Versioning and Iteration](https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-management)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
