← Blog

9 Prompt Engineering Techniques for Better LLM Output

2026-09-19 · 5 min read · SubToAPI Team

Prompt engineering techniques are the specific methods you use to structure inputs so a language model produces more accurate, consistent, and useful output. This isn't about "magic words"—it's a set of repeatable patterns: giving examples, breaking tasks into steps, constraining output format, and iterating based on what actually comes back. If you're building anything on top of an LLM, these techniques matter more than which model you pick.

Below are nine techniques that consistently improve output quality, with concrete examples you can adapt. Most work across models (Claude, GPT, open-source), though exact syntax varies slightly.

1. Be explicit about format

Models default to conversational prose unless told otherwise. If you need JSON, a table, or a specific structure, say so directly and show an example.

Return only valid JSON matching this shape:
{"name": string, "category": string, "confidence": number}

Do not include any text before or after the JSON.

Vague instructions like "give me structured output" produce inconsistent results. Show the exact shape you want.

2. Few-shot examples over abstract rules

Instead of describing what good output looks like, show 2-4 examples of input/output pairs. Models generalize from examples better than from adjectives like "professional" or "concise."

Input: "The app crashes on startup"
Output: {"severity": "high", "category": "bug"}

Input: "Add dark mode please"
Output: {"severity": "low", "category": "feature-request"}

Input: "Payment page shows blank screen"
Output:

This is one of the most reliable techniques because it removes ambiguity about tone, length, and format simultaneously.

3. Chain-of-thought for reasoning tasks

For math, logic, or multi-step analysis, asking the model to reason step by step before giving a final answer improves accuracy. This doesn't help with simple lookups or creative writing, but it matters for anything involving arithmetic, comparisons, or multi-condition logic.

Think through this step by step before giving your final answer.

Question: A user has 15 credits. Each API call costs 2 credits,
except calls with the "priority" flag which cost 3. If they make
4 regular calls and 2 priority calls, how many credits remain?

For production systems, you often want the reasoning hidden from the end user—ask the model to think through it, then output a final answer in a clearly marked field you can parse separately.

4. Role and context framing

Telling the model who it is and what context it's operating in shapes tone and scope. "You are a senior backend engineer reviewing a pull request" produces different output than "explain this code." Role framing is most useful when you need consistent tone across many requests, like a support bot or a code review assistant.

5. Constrain the negative space

Telling the model what not to do is often as important as what to do. If you keep getting unwanted preambles, caveats, or markdown formatting you didn't ask for, say so explicitly:

Do not include disclaimers, caveats, or phrases like "as an AI."
Do not use markdown formatting. Respond in plain text only.

6. Break complex tasks into steps

A single prompt asking a model to "research, summarize, and format as a report" will underperform three separate prompts chained together, each with a focused job. This is especially true for tasks with clear stages: extract data, then transform it, then format it. Chaining calls also makes debugging easier—you can inspect the output at each stage instead of guessing which part of one giant prompt went wrong.

7. Use delimiters to separate instructions from data

When your prompt includes user-provided content (a document to summarize, code to review), wrap it clearly so the model doesn't confuse instructions with data:

Summarize the text between the triple quotes in 3 bullet points.

"""
{user_content}
"""

This also reduces the risk of prompt injection, where content inside the data section tries to override your instructions.

8. Iterate with real failure cases

The biggest gains rarely come from a clever first draft—they come from collecting actual failures and adjusting the prompt to address them. Keep a small set of edge cases (ambiguous inputs, empty strings, adversarial phrasing) and re-test your prompt against them every time you change it. Treat your prompt like code: version it, test it, and don't change it blindly.

9. Set explicit length and stop conditions

Open-ended prompts tend to produce open-ended output. If you need a one-sentence answer, say "respond in one sentence" rather than hoping brevity happens naturally. For API integrations, combining this with a max_tokens limit gives you a hard ceiling and prevents runaway generation costs.

Applying this in production

These techniques work the same whether you're prototyping in a chat window or calling a model from code. The difference in production is that you need consistent, parseable output across thousands of requests, not just one good response.

If you're calling Claude through code, a well-structured request looks like this:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "max_tokens": 200,
    "messages": [
      {"role": "user", "content": "Classify this ticket and return JSON only:\n\n\"The export button does nothing when clicked\""}
    ]
  }'

SubToAPI turns your existing Claude access into a standard HTTPS API with sub_live_ keys, streaming, and usage metadata, so once you've nailed a prompt, you can wire it into your app without managing separate infrastructure. Check the quickstart or the messages endpoint docs for the full request format, and see pricing if you're evaluating it for a team.

Questions

Do prompt engineering techniques differ between models? The core techniques—few-shot examples, clear formatting, chain-of-thought—work across most modern LLMs. Exact syntax and how strongly a model follows instructions varies, so test your prompts against the specific model you're deploying with.

Is prompt engineering still relevant as models improve? Yes. Better models reduce how much prompting you need for basic tasks, but structured prompts still matter for consistent output format, cost control, and complex multi-step tasks. It shifts from "getting any answer" to "getting a reliable, parseable answer."

How do I test if a prompt change actually helped? Build a small set of representative test cases (including edge cases) and run them against both prompt versions. Compare outputs manually or with an automated check for the properties you care about—format validity, accuracy, length. Don't judge a prompt change from a single example.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →