new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Prompt Engineering · all subjects

separating data from instructions

13 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Prompt templates separate fixed skeleton from variable input

Prompt templates allow you to write a fixed prompt structure with placeholders for variable content that can be substituted later before sending to Claude. This enables reusable prompts where the same task runs repeatedly with different input data. Use f-strings or the format() method to substitute variable values into placeholders.

Use XML tags to separate input data from instructions

Wrap variable input data in XML tags (like <tag>content</tag>) to clearly delineate where input begins and ends. Claude was specifically trained to recognize XML tags as a prompt organizing mechanism. This prevents Claude from confusing instructions with user input, especially when the substituted content could be ambiguous or contain similar formatting to surrounding instructions.

XML tags solve ambiguity when instruction syntax matches input format

When variable input uses the same formatting patterns as the surrounding instructions (such as bullet points or hyphens), XML tags clarify which parts are data versus instructions. For example, a list of user-provided sentences mixed with example sentences of the same format requires XML tags to ensure Claude correctly identifies the actual input.

Use specific, relevant placeholder variable names for readability

Name placeholder variables descriptively and specifically (such as ANIMAL, EMAIL, SENTENCES, or TOPIC) rather than generic names (like A or DATA). This makes the prompt template understandable and parseable even without seeing the substitution, helping others understand the prompt structure at a glance.

Claude incorrectly interprets mixed instruction and data without separation

Without clear separation between instructions and variable input, Claude may treat instruction examples as part of the input data. For instance, if instructions say 'Each sentence is about an animal, like rabbits' and user input is a list of sentences with similar bullet-point formatting, Claude confuses the example with actual data without XML tag separation.

Prompt templates simplify repetitive tasks for third-party input

When building prompts that accept third-party user input, templating allows users to fill in variables without seeing or understanding the full prompt structure. This simplifies user interaction and reduces the burden on non-technical users who only need to provide specific data.

Example: Animal noise generator with variable substitution

```python ANIMAL = "Cow" PROMPT = f"I will tell you the name of an animal. Please respond with the noise that animal makes. {ANIMAL}" print(get_completion(PROMPT)) ``` This demonstrates basic prompt template structure where a variable is substituted into a fixed instruction using an f-string.

Example: Email politeness task without XML tags causes misinterpretation

```python EMAIL = "Show up at 6am tomorrow because I'm the CEO and I say so." PROMPT = f"Yo Claude. {EMAIL} <----- Make this email more polite but don't change anything else about it." print(get_completion(PROMPT)) ``` Without XML tag separation, Claude treats 'Yo Claude' as part of the email content to be rewritten, resulting in output beginning with 'Dear Claude'. The delineation is unclear after substitution, unlike in the template view.

Example: Email politeness task with XML tags prevents misinterpretation

```python EMAIL = "Show up at 6am tomorrow because I'm the CEO and I say so." PROMPT = f"Yo Claude. <email>{EMAIL}</email> <----- Make this email more polite but don't change anything else about it." print(get_completion(PROMPT)) ``` With XML tags wrapping the email content, Claude correctly identifies only the content within tags as the email to rewrite, preventing 'Yo Claude' from being included in the rewrite.

Example: List of sentences without XML tags causes mixed-format confusion

```python SENTENCES = """- I like how cows sound - This sentence is about spiders - This sentence may appear to be about dogs but it's actually about pigs""" PROMPT = f"""Below is a list of sentences. Tell me the second item on the list. - Each is about an animal, like rabbits. {SENTENCES}""" print(get_completion(PROMPT)) ``` Without XML tags, Claude incorrectly treats the instruction example '- Each is about an animal, like rabbits.' as part of the actual data list because the formatting matches.

Example: List of sentences with XML tags prevents format ambiguity

```python SENTENCES = """- I like how cows sound - This sentence is about spiders - This sentence may appear to be about dogs but it's actually about pigs""" PROMPT = f"""Below is a list of sentences. Tell me the second item on the list. - Each is about an animal, like rabbits. <sentences> {SENTENCES} </sentences>""" print(get_completion(PROMPT)) ``` XML tags wrap only the user-provided sentences, clearly showing Claude where the actual input data begins and ends, regardless of matching formatting with the instructions.

Input data handling in complex prompts

If Claude needs to process data, include it in the prompt within relevant XML tags (e.g., <history>, <question>, <legal_research>). Each piece of data should be enclosed in its own set of XML tags. Multiple pieces of data can be included. This element is flexible in ordering.

Use XML tags to separate data from instructions

When including input data that Claude needs to process, enclose each piece of data in its own set of XML tags. For example, use <legal_research> tags for legal documents, <question> tags for user questions, and <example> tags for response examples. This clearly delineates what is data to be processed from what are instructions to Claude.

Give your agent this brain