DEV Community

Sam Chen
Sam Chen

Posted on

10 LLM Prompting Techniques That Actually Work (No Hype)

A practical guide to getting better outputs from language models without the fluff


If you've spent more than five minutes working with large language models, you've probably heard it: "The prompt is everything."

But what does that actually mean? And more importantly, how do you write prompts that consistently produce useful results?

After spending way too much time experimenting with ChatGPT, Claude, and other models, I've narrowed down the techniques that genuinely move the needle. Here are the ones that work.

1. Be Embarrassingly Specific

Bad: "Write me a function to sort numbers"

Good: "Write a JavaScript function that sorts an array of integers in ascending order using quicksort, with comments explaining the partition step"

LLMs do better with context. More specificity = better outputs. It's that simple.

2. Use Role-Based Prompting

Start with what you want the model to be:

You are an experienced DevOps engineer with 10 years of 
Kubernetes expertise. A junior developer asks: [question]
Enter fullscreen mode Exit fullscreen mode

Models respond differently when given a frame of reference. They "adopt" the perspective you assign them.

3. The "Explain Your Thinking" Technique

Add this phrase before your ask:

"Before answering, think through the problem step-by-step. Explain your reasoning."

This simple addition reduces hallucinations and improves accuracy significantly. It forces the model to show its work.

4. Chain of Thought Prompting

Break complex tasks into smaller steps:

I want to build a feature. Let's break this down:
1. First, list the requirements
2. Then, identify potential issues
3. Finally, propose an implementation
Enter fullscreen mode Exit fullscreen mode

The model tends to stay more coherent and logical when problems are scaffolded.

5. Use Examples (Few-Shot Prompting)

Show the model what success looks like:

Convert these requirements to SQL WHERE clauses:

Example 1:
Requirement: "Users older than 25"
Output: WHERE age > 25

Example 2:
Requirement: "Active users in New York"
Output: WHERE status = 'active' AND city = 'New York'

Now convert this:
Requirement: "Premium users who haven't logged in for 30 days"
Output:
Enter fullscreen mode Exit fullscreen mode

Pattern recognition is what LLMs do best. Give them patterns to recognize.

6. Temperature and Creativity Control

If you're not experimenting with parameters:

  • Lower temperature (0.2-0.4): For factual, consistent outputs (coding, research)
  • Higher temperature (0.7-0.9): For creative work (brainstorming, writing)
  • Medium (0.5): For balanced responses

This isn't a prompt technique, but it dramatically changes your results.

7. Constrain the Output Format

Be explicit about structure:

Respond in JSON format with this structure:
{
  "summary": "brief overview",
  "pros": ["benefit1", "benefit2"],
  "cons": ["drawback1"],
  "recommendation": "your advice"
}
Enter fullscreen mode Exit fullscreen mode

Structured responses are easier to parse, validate, and use programmatically.

8. The "Devil's Advocate" Approach

Ask the model to challenge itself:

Propose a solution for [problem].
Then, explain why this solution might fail.
Finally, strengthen the solution based on those weaknesses.
Enter fullscreen mode Exit fullscreen mode

This reduces overconfident answers and produces more robust thinking.

9. Use Negative Examples

Show what not to do:

Generate a product description for our SaaS tool.

DON'T:
- Use marketing jargon
- Make claims you can't verify
- Use more than 100 words

DO:
- Focus on concrete benefits
- Be specific about features
Enter fullscreen mode Exit fullscreen mode

Constraints on what to avoid often work better than pure positive instructions.

10. The "Iterate and Refine" Loop

This isn't one technique—it's a meta-technique:

  1. Get the initial output
  2. Ask "What's missing?"
  3. Ask "Can you elaborate on X?"
  4. Ask "How would you improve this?"

Don't expect perfection in one shot. Treat LLM interaction like a conversation, not a transaction.


The Real Secret

The techniques that work best share something in common: they reduce ambiguity.

LLMs are pattern-matching machines. Every bit of clarity you add to your prompt is interpreted as additional pattern information. Vagueness gets filled in with hallucinations.

What NOT to Do

  • Don't assume the model understands your context. It doesn't read minds—it reads text.
  • Don't ask for legal/medical/financial advice and trust the output without verification.
  • Don't use jailbreak prompts expecting magic. You'll mostly just get garbage.
  • Don't be afraid to be verbose. Words are cheap; clarity is expensive.

Your Turn

What prompting techniques have you found actually work? I'm genuinely curious what's working in production for people.

Drop your go-to techniques in the comments—let's build a practical knowledge base together.

And remember: The best prompt is the one you'll actually use consistently.


Have strong opinions about prompt engineering? Disagree with my takes? Share them below. Let's actually solve this together instead of just hypothetically discussing it.

Top comments (0)