Skip to main content

Why Structure Matters

The longer a prompt gets, the more important its structure becomes. A 200 token prompt can be unstructured and still work. A 2000 token prompt with mixed instructions, context, examples, and input is almost guaranteed to underperform unless its parts are clearly delimited. Structure does three things at once. It makes the prompt parseable for the model, so it can distinguish instructions from data. It makes the prompt readable for your team, so you can maintain it over time. And it makes the output parseable for your code, so you can extract the result reliably. Inside PANTA OS, every assistant has a system prompt that benefits from the structure described on this page. The longer the system prompt, the more important the structure.

XML Tags

XML tags are the most flexible structuring tool because they can be nested, named freely, and parsed easily. Most modern models have been trained extensively on XML tagged prompts and respond particularly well to them. There is no canonical set of tag names. Pick names that describe what they contain, and use them consistently across your prompts.
The pattern: one tag per logical section, names that match what the section contains, and the input clearly separated from the instructions. The model can now parse this prompt as five distinct components instead of one undifferentiated wall of text. A few rules of thumb:
  • Use consistent tag names. If you call something <context> once, do not call it <background> later. Consistency reduces the chance of misinterpretation.
  • Nest where the structure has a natural hierarchy. Multiple documents go inside a <documents> tag, each as a <document> with an index attribute.
  • Refer to tags by name in your instructions. “Using the contract in the <contract> tags above, identify …” is clearer than “Using the contract above, identify …”.

JSON Output Contracts

When the output will be parsed by code, define the schema in the prompt. There are three ways to do this, in increasing order of reliability. The first is a description of the schema in prose:
The second is a JSON schema or example:
The third, and most reliable, is to use the structured output features of the API: response format constraints or tool use with a defined schema. These features force the model’s output to validate against a JSON schema before it is returned. They are the right answer for any production pipeline that consumes JSON. Even with structured output features enabled, keep the schema description in the prompt. The features constrain the shape; the prompt explains the meaning. Both matter.

System Prompt Anatomy

The system prompt is the place to put everything that should hold for the entire conversation: the role, the rules, the constraints, the format expectations. A clean system prompt has roughly six sections, in this order:
  1. Role and identity. Who the assistant is, what their expertise is, and who they are talking to.
  2. Core responsibilities. The tasks the assistant is expected to perform.
  3. Behavior rules. How the assistant should communicate: tone, formality, length, language.
  4. Constraints and refusals. What the assistant must not do, and what to do when asked.
  5. Output format. The default format for responses.
  6. Examples (optional). Two or three short interactions that demonstrate the rules.
A worked example for a customer support assistant:
This structure is not magic, but it covers the ground. Assistants built this way are easier to update, because each kind of change has an obvious place to go. The system prompts generated by the PANTA OS Assistant Wizard follow this skeleton, and the manual creator gives you the same scaffolding to fill in by hand.

Order of Elements

Within a prompt, order matters more than people expect. Recency bias in models is well documented: instructions placed at the very end of a prompt tend to be followed more reliably than instructions placed in the middle. A few practical guidelines:
  • Put the role and core rules at the top. They define the frame.
  • Put long context in the middle. Documents, transcripts, examples.
  • Put the immediate task at the end. “Now, given the document above, produce …” should be the last thing the model reads before it generates.
For long prompts that include both system instructions and user instructions, repeat critical constraints at both the top and the bottom. The redundancy is cheap and the reliability gain is real.

Delimiters for input

Always delimit the input clearly. The most common choices, in order of preference:
  • XML tags. <document>...</document>. The most flexible and best supported across modern models.
  • Triple backticks. .... Standard for code and unstructured text.
  • Triple quotes. """...""". The classic delimiter, still works.
  • Markdown headings. # Document followed by the content. Less precise but readable.
The wrong choice is no delimiter at all. When user input is concatenated directly into a prompt without delimiters, the model sometimes treats the input as additional instructions, which is both an output quality issue and a security issue (prompt injection).

A Complete Structured Prompt

Putting it all together for a realistic task:
Every section is named, the input is clearly delimited, the output contract is precise, and the final instruction is at the end where the model will weight it most. This structure scales: the same skeleton works for prompts of 500 tokens or 5000 tokens.

What Comes Next

Strong structure prevents most failures. The remaining failures, the ones where the model produces confident but wrong output, are addressed in Reducing Hallucinations.
Last modified on June 1, 2026