Structured prompts: organize complex instructions and inputs
A structured prompt separates content with different roles—such as instructions, background, examples, and user input—using headings, lists, delimiters, or tags. These boundaries can make the prompt easier for a model to interpret, but formatting alone does not guarantee compliance or factual answers. Plain text is enough for simple requests; add structure when content types are mixed or inputs recur.
Structured prompts: organize complex instructions and inputs
A structured prompt separates content with different roles—such as instructions, background, examples, and user input—using headings, lists, delimiters, or tags. These boundaries can make the prompt easier for a model to interpret, but formatting alone does not guarantee compliance or factual answers. Plain text is enough for simple requests; add structure when content types are mixed or inputs recur.
What problem do sections address?
When a prompt mixes what to do, what to consult, and how to answer, the boundaries can be unclear. If a customer question is simply appended to response rules, for example, a sentence inside the question may be mistaken for an instruction rather than quoted content. Headings or tags make each part’s role visible and also make prompts easier for people to review and maintain.
OpenAI documents Markdown headings and lists for showing logical sections and hierarchy, and XML tags for marking the boundaries of specific data such as reference documents. Anthropic likewise recommends descriptive XML tags to separate instructions, context, input, and examples. These are documented authoring practices, not a promise that the same formatting will improve every model or task.
When should you use Markdown or tags?
Use Markdown headings and lists for short instructions or a readable workflow. If the prompt contains a long user input or multiple documents, tags such as <input> or <document> make start and end points explicit. Choose descriptive, consistent tag names and wrap each document in the same structure. XML-like text is not a special authority for the model; it is a way to mark boundaries.
# Task
Answer the customer using only the scope of the policy below.
<policy>
{{policy_document}}
</policy>
<customer_question>
{{customer_question}}
</customer_question>
# Response requirements
- Do not guess about conditions absent from the policy.
- Ask for information needed to resolve anything not covered.
- Reply in English in no more than three sentences.This example separates two changing inputs; it does not describe a real policy or service. When inserting variables in application code, put each value in its intended location and check that user-provided text cannot close a tag or spill into another section. Delimiters are not a security boundary: text inside a tag can still contain malicious instructions. Control permissions, tool use, and access to sensitive data in the application itself.
How can you keep the structure useful?
Start with only the sections you need. Add separate identity, instructions, reference material, input, or output requirements when their roles differ; avoid wrapping a one-sentence request in layers of tags. Repeating the same rule in headings and tags, or placing conflicting rules in different sections, can make the prompt harder to follow. Treat section order as something to compare for your model and task, not a universal rule.
Evaluate with representative real inputs, including empty input and text containing special characters or tag-like strings. Check whether the model follows the intended sections, treats the input as data rather than new instructions, and respects the requested format. If output must be machine-readable JSON, distinguish asking for JSON in a prompt from a supported JSON Schema (OpenAI Structured Outputs) structured-output feature: the former is an instruction; the latter is a separate API capability that can strengthen format validation.
Sources
[OpenAI API: Prompt engineering](https://developers.openai.com/api/docs/guides/prompt-engineering) — Markdown and XML prompt boundaries and a common section sequence. Read 2026-11-22.
[Anthropic: Prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices) — separating instructions, context, input, examples, and documents with XML tags. Read 2026-11-22.