OverpayingForAIPricing desk

Lesson 5 of 8 · 9 min read · Beginner → Intermediate

Prompting basics for Llama

Open-weight instruct models reward clear structure. Learn the anatomy of a good prompt and see three before-and-after examples that work on Llama.

In this lesson you will

  • Structure a prompt with role, task, context, constraints and output format
  • Use a system prompt effectively on hosted and local Llama models
  • Fix three common beginner prompts so they produce usable output

Llama's instruct models follow instructions well, but they are less forgiving of vague prompts than the largest closed models. That is not a flaw to fight. It is a reason to write prompts with a clear structure, which also makes them cheaper because you get a usable answer on the first try instead of the third.

Anatomy of a prompt that works first timeFive parts. Most bad answers are missing two of them.RoleWho the model should be
“You are a pricing analyst…”
TaskThe one thing you want
“Rank these 4 plans by cost per 1K tokens.”
ContextFacts it cannot guess
paste the plan table, your usage
FormatShape of the answer
“a table, then a 2-line verdict”
ConstraintsWhat to avoid
“no marketing language; cite the source”
Cost angleA precise prompt costs a few hundred tokens more and saves the two or three retries that cost thousands.Asking for a short format (“3 bullets”) cuts output tokens — the expensive kind — by half or more.
Figure 1.The parts of a prompt that reliably improve output: a role, a specific task, the context it needs, constraints, and the format you want back.

The system prompt is your friend

On a hosted API or local runner you can set a system prompt that applies to the whole conversation. Put stable instructions there: who the model is, what tone to use, what format to return. Then keep each user message short. This saves tokens on every turn and keeps the model consistent.

In Meta AI you do not get a system prompt, so put the same instructions at the top of your first message. The structure still works, you just repeat it more often.

Example 1: rewriting an email

Before and after: the second version tells the model the audience, the goal and the length.
BeforeAfter
Make this email better: [email]You are an assistant that edits business email. Rewrite the email below so a busy client can read it in 30 seconds. Keep every fact. Lead with the decision I need from them. Max 120 words, plain English, no exclamation marks. Email: [email]

The before prompt produces something longer and more formal than you wanted, and you send a second message to fix it. The after prompt produces the right thing once. On a metered API, that halves the cost of the task.

Example 2: extracting data

Before and after: specifying the exact output format makes the result usable by code, and a small model can handle it.
BeforeAfter
What are the important details in this invoice? [text]Extract from the invoice text below. Return only JSON with keys: vendor, invoice_number, date (YYYY-MM-DD), total (number), currency (ISO code). If a value is missing, use null. No commentary. Text: [text]

Example 3: writing code

Before and after: language, constraints and a test make the answer far more likely to run first time.
BeforeAfter
Write a function to dedupe a listWrite a Python 3 function dedupe(items) that removes duplicates while preserving first-seen order. Items may be unhashable dicts; compare by json.dumps with sorted keys. Include a docstring and three assert-based tests. Return only code.

Habits that work on Llama

  • Say what format you want, and say "only" if you want no chatter around it.
  • Give one or two short examples of the ideal output for repetitive tasks. Open-weight models respond strongly to examples.
  • Ask for a plan first on complex tasks, then ask it to execute the plan. Two short calls often beat one long one.
  • Keep the context lean. Paste the relevant section, not the whole document, unless the whole document is the task.

Knowledge check

Which change most reliably lets you use a smaller, cheaper Llama model for a task?

Lesson FAQ

Does Llama support system prompts?

Yes, on hosted APIs and local runners. Meta AI does not expose one, so put the same instructions at the top of your first message there.

Why does Llama ignore part of my prompt?

Usually the prompt is long and the key instruction is buried. Move constraints and the output format to the end of the prompt or into the system prompt, and keep the context focused.

Do prompts written for ChatGPT work on Llama?

Mostly. Llama tends to need more explicit structure and examples. If a prompt works on a closed model but not on Llama, add a format specification and one example before switching to a bigger model.

Finished reading?

Mark it done to track your progress through the course.

Compare, calculate, decide — for Llama

If our calculators helped you cut down on hidden AI wallet leaks, consider buying us a coffee. A tiny fraction of your savings keeps our pricing indexes updated daily.

Not sure which AI is cheapest for your use case? Find out in 30 seconds — no signup required.

AI cost intelligence

Stop overpaying for AI tools

Join the OverpayingForAI list for pricing updates, cheaper alternatives, and practical buying guidance.

Now tracking 50+ AI tools, models, platforms, subscriptions, coding tools, and automation products.

We use your email only for OverpayingForAI updates. Unsubscribe anytime.