← Blog

How to Write Effective Prompts for LLM Apps

2026-11-23 · 5 min read · SubToAPI Team

Writing effective prompts for LLM apps means giving the model enough structure, context, and constraints that it produces the same quality of output on the hundredth call as it did on the first test in a chat window. Most prompt failures in production aren't because the model is "bad" — they happen because the prompt relies on implicit assumptions that worked once by luck and then broke under real user input, edge cases, or longer conversations.

The fix isn't a magic phrase or a trick. It's treating prompts like code: version them, test them against real inputs, and design them around the specific task the model needs to do — answering, extracting, classifying, calling tools, or generating long-form content. Below is a practical framework you can apply to any LLM-backed feature, whether you're calling the API directly or routing through a gateway like SubToAPI.

Start with the Job, Not the Wording

Before writing a single sentence of prompt text, define what "correct" output looks like. Is the model:

Each of these needs a different prompt shape. A prompt that's great for creative writing will produce messy, inconsistent JSON for data extraction. Decide the job first, then write the prompt to match it.

Separate System Instructions from User Input

The single biggest reliability win is keeping persistent behavior (role, constraints, output format) in the system prompt, and letting user-specific content flow through the user message. Mixing the two causes prompts to drift as inputs get longer or weirder.

const response = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "claude-sonnet-4",
    system: "You are a support ticket classifier. Respond with only one word: billing, technical, or account. No explanation.",
    messages: [
      { role: "user", content: "I was charged twice this month, can you help?" }
    ],
    max_tokens: 10
  })
});

Notice the system prompt does three jobs at once: defines the role, constrains the output format, and explicitly forbids extra text. All three matter — without the last one, many models will add a sentence of explanation even when you asked for one word. See the messages docs for the full request shape if you're building this against SubToAPI.

Be Explicit About Format, Length, and Edge Cases

Vague instructions produce vague — or inconsistently formatted — output. Instead of "summarize this," specify:

Summarize the following support transcript in exactly 3 bullet points.
Each bullet must be under 15 words.
If the transcript contains no actionable issue, respond with: "No action needed."
Do not include greetings, apologies, or sign-offs.

This kind of specificity removes the ambiguity that causes output to vary call to call. It also makes your downstream parsing code simpler, because you're not guessing what shape the response will take.

Use Examples for Anything Format-Sensitive

For tasks like data extraction, classification with custom categories, or matching a specific writing style, one or two well-chosen examples (few-shot prompting) outperform long written instructions. Show the input and the exact expected output:

Input: "Refund my order #4821, it arrived broken"
Output: {"category": "refund", "order_id": "4821", "reason": "damaged"}

Input: "How do I change my email address?"
Output: {"category": "account", "order_id": null, "reason": "email_change"}

Two or three examples like this anchor the model's output format far more reliably than a paragraph describing the schema. Keep examples representative of real production inputs, including messy or incomplete ones — not just the clean happy path.

Constrain Before You Expand

A common mistake is writing an open-ended prompt and then trying to patch bad outputs with more and more instructions. It's usually faster to start tight and loosen only where needed:

  1. Start with strict output format and length limits
  2. Test against 10–20 real or realistic inputs
  3. Loosen constraints only where the strict version produces worse answers
  4. Re-test after every change

This is the same iteration loop you'd use debugging code — change one variable, observe the effect, repeat.

Handle Multi-Turn Context Deliberately

In conversational apps, prompt effectiveness degrades as conversation history grows. Repeat critical constraints (format, scope, forbidden topics) in the system prompt rather than relying on the model to remember an instruction from five turns ago. If your app streams responses to the user, make sure your prompt doesn't depend on the full output being generated before any validation happens — see the streaming docs if you're building a chat-style interface.

Test Prompts Like You Test Code

Before shipping a prompt change, run it against a fixed set of representative inputs and compare outputs against expected results. A simple test harness:

const testCases = [
  { input: "My card was declined", expected: "billing" },
  { input: "The app crashes on login", expected: "technical" },
  { input: "I can't reset my password", expected: "account" }
];

for (const test of testCases) {
  const result = await classify(test.input);
  console.log(result === test.expected ? "PASS" : `FAIL: ${result}`);
}

This catches regressions when you tweak wording, swap models, or adjust temperature — the same way unit tests catch regressions in application code.

Match the Prompt to the Model's Capabilities

If your prompt instructs the model to call external tools or APIs, the structure is different from a plain text prompt — you need clear tool descriptions and decision criteria, covered in the tools documentation. If you're just getting started integrating an LLM into your app, the quickstart guide walks through the request format end to end, and pricing covers how usage is billed across plans if you're evaluating cost against prompt length and output verbosity.

questions

Does a longer, more detailed prompt always produce better output? No. Longer prompts help when the extra detail resolves real ambiguity — format, edge cases, constraints. Past that point, extra wording can dilute the instructions that matter and increase token cost without improving results. Test shorter versions against the same inputs before assuming more detail is better.

Should I put instructions in the system prompt or the user message? Persistent behavior — role, output format, constraints — belongs in the system prompt so it stays stable across turns. Task-specific content, like the text to summarize or the question to answer, belongs in the user message. Mixing them causes instructions to get lost as conversations grow.

How many examples should I include in a prompt? Two or three well-chosen, representative examples are usually enough for format-sensitive tasks like extraction or classification. More examples increase token usage and latency without reliably improving accuracy — focus on example quality and diversity of edge cases over quantity.

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 →