Prompts Rules and Structure
When writing prompts that utilize tokens and parameters (often used in
APIs for Large Language Models like OpenAI's GPT, Anthropic's Claude, or local
models), the best format is structured text utilizing clear delimiters,
variable placeholders, and explicit configuration parameters.
Structuring your prompt cleanly helps the model distinguish between
instructions, context, and user inputs, leading to more predictable and
accurate outputs.
Recommended Prompt Structure
The industry-standard format combines Markdown headers, XML
tags (which LLMs parse exceptionally well), and JSON/YAML for
parameter configuration.
Markdown
### System Instructions (Role &
Constraints)
You are an expert financial analyst.
Your task is to summarize the provided quarterly report into three bullet
points. Keep the tone objective and professional.
<document_content>
{{document_text}}
</document_content>
Summarize the document above for the
Q3 fiscal period.
### Parameter Configuration (API
payload example)
{
"model": "gpt-4o",
"temperature": 0.2,
"max_tokens": 150,
"top_p": 1.0,
"frequency_penalty": 0.0,
"presence_penalty": 0.0
}
Key Components Explained
1. Delimiters (XML Tags or Markdown)
Use tags like <context>, ###, or --- to separate sections. LLMs understand hierarchy
through formatting.
- Why it matters: It prevents prompt injection
(where user input overrides system instructions) and ensures the model
knows what data to act upon versus how to act.
2. Variable Placeholders ({{variable}})
If you are programmatically generating prompts, use clear placeholders
(like double curly braces or Python-style {variable} formatting) so your backend can easily inject token values.
3. Parameter Best Practices
When passing parameters alongside your token text, tune them based on
your goal:
- temperature (0.0 to 1.0 or 2.0):
- Use low values (0.0 – 0.3)
for deterministic tasks like data extraction, classification, or coding.
- Use higher values (0.7 – 1.0)
for creative writing, brainstorming, or open-ended dialogue.
- max_tokens: Always set a ceiling to control
costs and prevent runaway responses, ensuring it is large enough to
complete the intended output without cutting off mid-sentence.
- top_p (Nucleus Sampling): Often adjusted alongside
temperature. Lowering it (e.g., to 0.9) restricts the model to only the
most probable token choices.
Sometimes the tag looks like: #OptimizeLongevity #diet
#OutDoorActivities.
When tags look like #OptimizeLongevity
#diet #OutDoorActivities, they serve a completely different purpose than API tokens or code
parameters. Instead of structuring code or data, these are semantic metadata
tags or categorical keywords injected directly into the prompt text.
This format is
typically used for three main reasons:
1. Zero-Shot Context and Domain Injection
In modern prompt engineering,
prepending or appending hashtag-style keywords tells the LLM the context,
domain, or thematic boundaries of the task without writing a long paragraph.
- How it works: The model's training data associates tokens like #diet or #OptimizeLongevity with a vast web of related
concepts (nutrition, health metrics, fitness, habits).
- Effect: It instantly primes the model's neural network to lean toward a
specific vocabulary and perspective.
2. Output Formatting & Classification
If you are asking the LLM to
categorize content, generate social media copy, or tag data, embedding hashtags
directly into the prompt acts as an implicit few-shot example of how you
want the final output to look.
Example of a Prompt using this format:
Markdown
Analyze the user
lifestyle choice below and provide a response.
At the end of your
response, append 3 relevant categorical tags matching this exact format:
:#OptimizeLongevity #diet #OutDoorActivities
<user_input>
"I spend my
weekends hiking and meal-prepping green vegetables for the workweek."
</user_input>
3. Automated Parsing (Regex / Post-Processing)
If you are writing a script that
interacts with an LLM via tokens and parameters, forcing the model to output
specific hashtag formats makes it very easy for your code to extract data
using Regular Expressions (Regex).
- Your backend code can easily search the raw text
string for words starting with # to automatically categorize the AI's output, push
it into a database, or route it to another application.
Summary of Tag Styles in Prompts
|
Tag Style |
What it is |
Best Used For |
|
### Header
or # Section |
Markdown
syntax |
Structuring
instructions, separating context, and guiding the LLM's logical hierarchy. |
|
<tag>Content</tag> |
XML tags |
Enclosing dynamic variables, user
inputs, or raw data blocks so the model doesn't confuse instructions with
data. |
|
#Keyword #Topic |
Semantic/Metadata
hashtags |
Priming
topical context, matching social media output styles, or easy programmatic
regex parsing. |
What is the process:
from prompt -> Tokens -> Parameters ->?
The complete lifecycle of a request—from the moment you type a prompt to
the final output generated by the AI—follows a structured pipeline through the
model's architecture and inference engine.
The Complete Process Pipeline
[1. Prompt] ➔ [2. Tokenization] ➔ [3. Parameter Application] ➔ [4. Inference & Sampling] ➔ [5. Output Generation]
Step-by-Step Breakdown
1. The Prompt (Human Input)
- What it is: The raw text, instructions, and
context you write (e.g., using Markdown, XML tags, or metadata hashtags
like #OptimizeLongevity).
- Role: It defines the goal, provides
background context, and sets the behavioral constraints for the AI.
2. Tokenization (Breaking Text into Numbers)
- What it is: LLMs cannot read raw English
words or characters directly. A tokenizer breaks your prompt down
into smaller chunks called tokens (which can be whole words, parts
of words, or punctuation marks). Each token is then mapped to a unique
numerical ID from the model's vocabulary dictionary.
- Example: The word "Optimize" might become token 12543, and "Longevity" might become token 4821.
- Role: It translates human-readable
text into a sequence of numbers that the neural network can mathematically
process.
3. Parameter Application (Guiding the Engine)
- What it is: Before the model starts
generating a response, the configuration parameters you set (like temperature, top_p, and max_tokens) are loaded into the inference
engine's math formulas.
- Role: Parameters act as the control
knobs for the engine. They dictate how the model reads the math and
how it selects the next numbers.
4. Inference & Sampling (The Core Calculation)
- What it is: The model processes your input
tokens through its neural network (transformer layers) to calculate a
probability distribution for the very next token.
- How parameters shape this step:
- Temperature flattens or sharpens the
probability curve (making choices more random or more predictable).
- Top-P / Top-K cut off unlikely token choices
to keep the output coherent.
- Once a single next token is
selected based on these rules, it is appended to the input sequence, and
the process repeats to predict the token after that.
5. Output Generation (The Final Destination)
- What it is: The sequence of newly generated
numerical token IDs is passed through a detokenizer, which stitches
the numbers back together into human-readable text.
- Role: This delivers the final response
back to your screen or application interface, stopping when it hits a
natural "stop token" (end of text) or reaches your pre-set max_tokens limit.
What is the best practice
to write tags: #OptimizeLongevity or #Optimize-longevity or #optimize
longevity?
When it comes to writing tags in
prompts or for data processing, the best practice depends heavily on how the
text is being parsed (by humans, code, or the AI model itself).
Comparison of the Three Formats
|
Format |
Style Name |
Best Use Case |
Pros & Cons |
|
#OptimizeLongevity |
PascalCase
(CamelCase) |
Social
media, modern prompt context, human readability |
Pros: Clean, widely recognized by
platforms, keeps multi-word concepts unified.
Cons: Slightly harder for basic code to
parse without regex. |
|
#Optimize-longevity |
Kebab-case with hash |
Coding, database slugs, file naming,
strict system tags |
Pros: Extremely reliable for automated
scripts and URL routing.
Cons: Looks less natural in prose. |
|
#optimize longevity |
Space-separated
/ Natural |
Casual
reading, broad topic hinting |
Pros: Reads like normal English.
Cons: Breaks automated parsing (code will
treat #optimize
as the tag and longevity
as regular text). |
Best Practice Recommendations
1. For LLM Prompting
& Metadata: Use PascalCase (#OptimizeLongevity)
If you are using hashtags in a prompt
to prime the AI or categorize a concept, PascalCase is the industry
standard.
- Why: Capitalizing the first letter of
each word makes it immediately readable to both humans and LLMs. The AI
easily parses it as a single compound concept rather than two separate
words.
2. For Code, APIs,
and Database Integration: Use Kebab-Case (#Optimize-longevity) or Snake_Case (#optimize_longevity)
If your prompt output is going to be
scraped, filtered, or parsed by a script or database:
- Why: Spaces break most text parsers. Hyphens or underscores ensure that
your backend code treats the entire string as a single unified entity.
3. Avoid
Space-Separated Tags (#optimize longevity) in Code Contexts
Never use spaces if you expect an
automated system to pull the tag later. A regular expression (regex) looking
for a hashtag will stop at the first space, meaning #optimize longevity will only capture #optimize, completely dropping the rest of the
context.
Comments
Post a Comment