A vague prompt is how official figures go wrong. If you tell a model, “Write something nice to Ananya’s parents about the fee,” it may invent a balance, a due date, or a discount you never offered. Prompt engineering, for a developer, is the craft of giving the model a job it can finish and a shape your code can check.
You will tighten a tuition-centre reminder: clear instructions, a short example, and JSON output that Python or PHP can validate. The same habits apply whether you call the API with requests or with cURL.
Key takeaways
- A useful prompt states the role, the task, the facts you already know, and the limits (“do not invent amounts”).
- Put official names, dates, and rupee figures in the prompt from your own data.
- A short example (few-shot) often steadies the format more than a long lecture.
- Ask for JSON with named fields, then validate the keys and types in code before you use the result.
- If validation fails, retry or fall back to a hand-written message — do not show broken output to a parent.
What goes wrong with a vague prompt
Compare these two user messages for the same job at Shree Vidya Tuition Centre:
Write a reminder about a pending fee.
Write a 2-sentence reminder for a parent. Student: Ananya Sharma.
Balance: ₹1,200. Month: November. Do not add any other amount or date.
The first leaves the model free to guess. The second supplies the facts and a limit. That is the whole skill in miniature: you own the data; the model owns the wording.
A prompt with four parts
Most reliable developer prompts have four parts, even if they sit in two messages (system + user):
- Role. Who the model is pretending to be, in one line: “You write short, polite messages for a tuition centre in India.”
- Task. What to produce: two sentences, or a JSON object, or both.
- Facts. The student name, the balance, the month — copied from your records.
- Constraints. What not to do: no invented fees, no extra dates, no medical or legal advice, keep it under 60 words.
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You write short, polite messages for a tuition centre in India. Use the rupee amounts and dates given to you. Never invent or change a number. If a fact is missing, say so instead of guessing."
},
{
"role": "user",
"content": "Student: Ananya Sharma\nBalance: ₹1,200\nMonth: November\nTask: write a 2-sentence payment reminder."
}
]
}
Notice the facts are listed as labelled fields, not buried in a story. Models follow labels more consistently, and you can build that user message with an f-string or sprintf from a database row.
Give one or two examples
When you care about format, show a finished example (few-shot). One good example is often enough for a short reminder. Put the example in the system message, or as a prior user/assistant pair:
{
"messages": [
{"role": "system", "content": "You write fee reminders. Follow the example format exactly."},
{"role": "user", "content": "Student: Rahul Iyer\nBalance: ₹800\nMonth: October"},
{"role": "assistant", "content": "Dear parent, this is a reminder that Rahul Iyer has a balance of ₹800 for October tuition. Please pay at the Shree Vidya office at your convenience."},
{"role": "user", "content": "Student: Ananya Sharma\nBalance: ₹1,200\nMonth: November"}
]
}
The example teaches tone and structure without a long style guide. Keep it honest: if the live row says ₹1,200, the example should not use a different currency format or the wrong name.
Ask for JSON, then check it in code
Free text is hard to file, email, or translate. For anything your program will store or display in pieces, ask for JSON with a fixed set of keys:
Return only a JSON object, no markdown, with these keys:
- greeting (string)
- body (string)
- amount_inr (integer, the balance in rupees, copied exactly from the facts)
A valid reply might look like this:
{
"greeting": "Dear parent,",
"body": "Ananya Sharma has a balance of ₹1,200 for November tuition. Kindly pay at the office this week.",
"amount_inr": 1200
}
Your code must not trust that object until it has been parsed and checked. This small Python check was run on this machine:
import json
REQUIRED = {"greeting", "body", "amount_inr"}
def parse_reminder(raw: str, expected_amount: int) -> dict:
data = json.loads(raw)
if not isinstance(data, dict):
raise ValueError("Expected a JSON object.")
missing = REQUIRED - data.keys()
if missing:
raise ValueError("Missing keys: " + ", ".join(sorted(missing)))
if data["amount_inr"] != expected_amount:
raise ValueError(
"amount_inr did not match the official balance "
f"({expected_amount})."
)
if not data["greeting"] or not data["body"]:
raise ValueError("greeting and body must be non-empty strings.")
return data
raw = '{"greeting":"Dear parent,","body":"Ananya Sharma has a balance of ₹1,200 for November tuition.","amount_inr":1200}'
print(parse_reminder(raw, 1200))
If amount_inr comes back as 1500 when your database says 1200, you reject the result. That single check is the difference between a helpful draft and an embarrassing message. The same idea in PHP is json_decode($raw, true) plus a few isset and integer comparisons.
Ask for “JSON only, no markdown fences.” Models sometimes wrap output in fences. Failing clearly is safer while you are learning: you will see the problem instead of accepting a string that is not quite JSON.
Try this
Write a bad prompt (“remind them about fees”) and a good prompt (role, facts, constraints, JSON keys) for Meera Patel, balance ₹2,450, month December. Then, without calling an API, take the sample JSON above, change amount_inr to 999, and run parse_reminder with expected_amount=2450. You should get a validation error. That is the behaviour you want in production.
A few habits that travel
- One job per call when you can — “write the reminder” is easier to check than a prompt that also plans next term.
- Put limits in writing (“do not invent amounts”), rather than hoping the model will be careful.
- Keep a tiny test set of rows with known balances, and re-run it when you change the prompt. Never log the API key.
What you learned
- Clear prompts state a role, a task, official facts, and constraints.
- A short example steadies tone and format.
- JSON output is only safe after your code has parsed it and checked keys and values, including rupee amounts.
- These habits are language-agnostic: they sit in the prompt and in the validation layer, whether you call the API from Python or PHP.
Quick quiz
-
1. A prompt says only “Write a fee reminder.” What is the main risk?
- A) The model cannot write short sentences
- B) It may invent a balance, a date, or a name you never supplied
- C) JSON will be illegal in India
Show answer
B. Without facts and constraints, the model will fill the gaps. Official figures must come from your records.
-
2. Why give one example in the messages?
- A) So the model can copy the student name from the example into every reply
- B) To show the tone and format you want, without a long style lecture
- C) Examples replace the need for an API key
Show answer
B. Keep the example’s facts distinct from the live row, so the model does not reuse the wrong name or amount.
-
3. The model returns JSON with
amount_inr: 1500but your database says 1200. What should the program do?- A) Trust the model and email the parent
- B) Reject the result (or retry), because the official balance did not match
- C) Average the two numbers
Show answer
B. Validation exists for this case. Do not send a wrong rupee amount.
-
4. Where do the four prompt parts usually belong?
- A) Role and constraints in a system message; facts and the task in the user message (a common, clear split)
- B) Only in comments in your Python file, never in the API request
- C) In the API key header
Show answer
A. That split is a convention, not a law, but it is easy to build and easy to test. The key header is only for authentication.
Next lesson
Once you can write a tight prompt and validate JSON, you are ready for a harder design: a retrieval-augmented FAQ bot that answers only from your own notes (fees, timings, batch days) instead of from the model’s memory. That is the expert-level lesson in this study path.