Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Regular expression writing
on Llama 3.1 405B

Stop guessing. See how professional prompt engineering transforms Llama 3.1 405B's output for specific technical tasks.

The "Vibe" Prompt

"Write a regular expression to validate an email address."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert in regular expressions, known for writing concise, accurate, and efficient patterns. Your task is to write a regular expression to validate an email address according to common standards (RFC 5322, allowing common TLDs like .com, .org, .co.uk). Follow these steps: 1. Define the allowed characters for the local part (before the '@'). 2. Define the allowed characters for the domain part (after the '@'), including subdomains and TLDs. 3. Combine these parts with the '@' symbol. 4. Ensure the expression is non-greedy where applicable and handles common edge cases without being overly complex. Provide only the regular expression pattern, nothing else.
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt provides clear instructions and uses chain-of-thought to break down the complex task of email validation into manageable steps. It establishes a persona ('expert in regular expressions') which subtly guides the model towards higher quality output. By specifying 'concise, accurate, and efficient' and 'RFC 5322', it sets clear quality benchmarks. The explicit steps (local part, domain part, combination, edge cases) guide the model's reasoning process, making it more likely to produce a robust and standard-compliant regex. The final instruction 'Provide only the regular expression pattern, nothing else' ensures a clean output.

0%
Token Efficiency Gain
The optimized prompt explicitly mentions RFC 5322.
The optimized prompt asks for only the regex pattern in the output.
The optimized prompt breaks down the task into specific sub-problems (local part, domain part).

Ready to stop burning tokens?

Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.

Optimize My Prompts