Prompt Engineering Basics: From Test to Production
Start with a Testable Task Definition
Prompt engineering is the process of giving a language model enough context, constraints, and examples to produce a useful result consistently. For developers, the goal is not a clever one-line prompt. It is a repeatable interface between your application and an LLM.
Begin by writing the task in a form you could test. Define the input, desired output, audience, allowed assumptions, and failure behavior. For example, instead of asking, Summarize this support ticket, specify: summarize the ticket in three bullets, identify urgency as low, medium, or high, list requested actions, and return plain JSON. This turns an ambiguous request into a contract your code can validate.
- Input: ticket subject, message, customer tier, and prior messages.
- Output: a fixed schema with summary, urgency, and actions fields.
- Constraints: do not invent facts; use null when information is missing.
- Fallback: flag unclear requests for human review.
Build a Prompt with Clear Sections
A reliable prompt usually separates instructions from data. Put stable behavioral rules first, then provide the changing user content in clearly labeled sections. Delimiters such as XML-style tags are useful because they make boundaries obvious to both people and models.
Use an instruction hierarchy: define the role, task, output format, quality rules, and finally the input. Keep instructions direct. State what the model should do instead of only listing what it should avoid. For structured application workflows, require valid JSON and describe every field, including accepted enum values.
For example, an extraction prompt can say: Extract invoice data from the document. Return an object with vendor_name, invoice_number, total_amount, currency, and confidence. Set unknown values to null. Return JSON only. Your application should still parse the response and handle validation failures, because prompting improves reliability but does not replace defensive programming.
Use Examples When Rules Are Not Enough
Few-shot examples are especially valuable when output style, classification boundaries, or transformations are difficult to express as rules. Include two to five representative input-output pairs, covering normal cases and one edge case. Keep examples close to the real traffic your service will receive.
Do not add examples just to make a prompt longer. Each example consumes tokens and can bias the model toward a narrow pattern. Start with zero-shot instructions, add an example when evaluations show a recurring failure, and remove examples that do not measurably improve results.
Evaluate Before You Ship
Create a small evaluation set before integrating a prompt into production. Include at least 20 to 50 realistic cases, with expected properties rather than only ideal wording. A support classifier might be evaluated on correct category, correct escalation decision, valid JSON, and absence of fabricated details.
Run the same dataset whenever you change the prompt, model, temperature, or output parser. Record the prompt version, model name, latency, token usage, and pass rate. This makes prompt changes reviewable in the same way as code changes. For creative generation, use a human scoring rubric; for extraction and classification, automate as many assertions as possible.
Control Variability, Cost, and Safety
Use a lower temperature for extraction, routing, and code generation where consistency matters. Reserve higher values for brainstorming or varied marketing copy. Limit output length, request concise answers, and send only the context needed for the task. Token discipline lowers cost and often improves focus.
Treat user-provided text as untrusted data. Clearly isolate it from system instructions, avoid granting the model direct authority over sensitive actions, validate tool arguments on the server, and require confirmation for irreversible operations. When a model can call tools, enforce permissions in application code rather than relying on prompt wording.
Deploy Through a Compatible, Cost-Conscious API
Once your evaluation passes, move the prompt into a versioned template and call it through your existing SDK. 59API is a practical option for developers who need low-cost, pay-as-you-go access to native official-quality Claude models, including Opus, Sonnet, Haiku, and Fable, as well as GPT models. Its API base URL is https://api.59api.com, and compatibility with Claude Code, Codex, and OpenAI SDK workflows means many projects only need a base URL and API key configuration change.
This is useful for prompt iteration: you can compare capable models, route simple jobs to faster lower-cost options, and keep production spending visible without accepting a model downgrade. 59API also offers a referral rebate. When you are ready to run your evaluation set against real APIs, consider signing up for 59API and begin with a small, measured production workload.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite