Best practices · AI
Prompt Engineering Best Practices
Opens with creditsVendor-neutral prompt engineering best practices, checked against the official prompting guides from Anthropic, OpenAI and Google. It covers clear instructions, prompt structure and long context, few-shot examples, reasoning and prompt chaining, output and parameter control, and how to test, iterate on and maintain prompts as models change.
What you will learn
6 chapters · about 18 min
1Clear instructions and contextMost bad outputs come from prompts that leave the model to guess. These practices close the gaps a reader with no background would fall into.4 practices · 3 min
2Prompt structure and long contextA prompt that mixes instructions, documents and examples needs clear boundaries. These practices make each part easy for the model to find and hard to confuse.4 practices · 3 min
- Examples and few-shot promptingExamples are one of the most reliable ways to steer format, tone and structure. These practices make them teach the pattern without being copied word for word.4 practices · 3 minOpens with credits
- Reasoning, decomposition and prompt chainingNewer models reason internally, which changes how much step-by-step prompting you need. These practices cover when to split work and how to match prompts to the kind of model.4 practices · 3 minOpens with credits
- Output format and model settingsThe shape of the answer and the sampling settings matter as much as the instructions. These practices keep output predictable and avoid settings that newer models no longer need.4 practices · 3 minOpens with credits
- Testing, iteration and upkeepA prompt is only better if you can show it. These practices turn prompt writing from guesswork into a loop you can measure and maintain.4 practices · 3 minOpens with credits
About this guide
Prompt engineering is the part of building with language models that looks easy and is not. Anyone can write a prompt that works on the three inputs they tried. Writing one that behaves the same way on thousands of real inputs, survives a model upgrade and can be changed safely by a teammate takes a set of habits. These prompt engineering best practices are those habits.
The advice here is vendor-neutral. It is drawn from the prompting guides that Anthropic, OpenAI and Google publish for their own models, and where those guides agree, the practice is presented as general advice. Where they differ, for example on where long context belongs or which sampling settings to touch, the guide says so and tells you to settle it with your own tests rather than with folklore.
Two ideas run through every chapter. First, a model is like a capable new colleague with no background on your task: whatever you leave unsaid, it has to guess. Second, a prompt change is only an improvement if you can measure it. All three vendors put success criteria and a test set before any prompt tuning, and so does this guide.
Read the chapters in order if you are new to writing prompts. If you already ship LLM features, jump to the chapter on reasoning and prompt chaining or the one on output control, where newer models have changed what works.
Common questions
What is prompt engineering?
Prompt engineering is the practice of writing and testing the instructions, context and examples you send to a language model so that it produces the output you need, reliably. It includes structuring the prompt, choosing examples, controlling the output format and measuring changes against a test set.
How many examples should a few-shot prompt have?
Anthropic recommends 3 to 5 relevant, diverse examples for best results, and Google recommends including few-shot examples in general while warning that too many can cause overfitting. Start with three varied examples, then test whether adding or removing one changes your scores.
Should I still tell models to think step by step?
On reasoning models, usually not. Google says Gemini 3 thinks internally so explicit step-by-step reasoning is usually unnecessary, and OpenAI suggests giving reasoning models a goal rather than detailed steps. On fast non-reasoning models, explicit steps can still help. Test both on your own data.
Where should long documents go in a prompt?
Anthropic and Google both recommend putting long documents first and the question or instructions at the end. Anthropic reports that a query at the end can improve quality by up to 30 percent in its tests. Wrap each document in tags with its source so the model can cite it.
Should I lower the temperature for more accurate answers?
Not by default. Google recommends keeping Gemini 3 sampling settings at their defaults and warns that a temperature below 1.0 can cause looping on complex reasoning. Use clear instructions, examples and structured output for consistency, and change sampling settings only if your evals show a gain.
Sources (5)
Checked against these, last on 13 October 2026.
- Prompting best practices, Anthropic docsplatform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices
- Prompt engineering overview, Anthropic docsplatform.claude.com/docs/en/build-with-claude/prompt-engineering/overview
- Prompt engineering, OpenAI docsdevelopers.openai.com/api/docs/guides/prompt-engineering
- Prompt design strategies, Google AI for Developersai.google.dev/gemini-api/docs/prompting-strategies
- Effective context engineering for AI agents, Anthropic Engineeringwww.anthropic.com/engineering/effective-context-engineering-for-ai-agents
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allCheat sheets
See allBest practices
See all- Best Practices for Building LLM AppsHow to build LLM apps and agents that hold up in production: prompts, evals, prompt injection, tool permissions, cost, logging and privacy.
- Best Practices for AI Coding AssistantsHow to get reliable code from AI coding assistants and agents: instruction files, task prompts, verification, review, security, dependencies and session hygiene.
- Best Practices for Building AI AgentsHow to design AI agents that finish real tasks: when to use one, tool design, context and memory, control loops, MCP and agent security, and evaluating agent runs.
Checklists
See all- RAG Production ChecklistA RAG production checklist: chunking, embeddings, hybrid search, reranking, per-user permissions, citations, evals, re-indexing and cost, with how to verify each check.
- LLM Evaluation ChecklistAn LLM evaluation checklist: success criteria, eval datasets, code and model graders, judge calibration, agent evals, safety tests and production monitoring, with how to verify each check.
- AI Feature Launch ChecklistAn AI feature launch checklist: use case fit, evals, UX for errors, disclosure, human override, abuse filters, rate limits, cost caps, prompt privacy, monitoring and rollback.
Project structures
See all- GenAI RAG app (FastAPI) project structureFor developers turning a "chat with your documents" demo into an app people can rely on. A FastAPI backend where every layer has a home: ingestion workers, retrieval, prompts as versioned files, model clients with fallbacks and cost caps, guards, evals that gate CI, and tracing, so a wrong answer can be traced to the step that caused it.
- AI agent with an MCP server project structureFor developers who want to give AI assistants safe access to their own data or API. A TypeScript MCP server built on the official SDK, organised by feature (tasks, projects) with each feature owning its tools, resources and prompts, served over stdio for local hosts and Streamable HTTP with OAuth for remote ones, plus a small agent and the evals that prove a model can use it.
- Machine learning project project structureFor students and analysts whose model works in a notebook and now needs to be reproducible, reviewable, served and watched. It starts from the Cookiecutter Data Science v2 layout (immutable raw data, numbered notebooks, a real Python package) and grows into versioned data with DVC, typed parameters, data validation with pandera, experiment tracking and a model registry with MLflow, a FastAPI prediction service, drift monitoring and, for a team, scheduled retraining, model cards, fairness checks and shadow deployment.
Career questions
See all- Which AI tools do employers expect junior developers to know in 2026?Employers rarely require a specific brand. They expect you to use an AI coding assistant well (in the editor and in the terminal), to review and test what it produces, to call an LLM API in a small feature, and to explain when you would not use AI. Pick one assistant, learn it properly, and show judgement in your projects.
- How do I use AI to become a better engineer instead of becoming dependent on it?Decide the job AI does before you open it. Use it as a tutor, reviewer and sparring partner that explains and challenges, not a vending machine that hands you finished code. Attempt first, ask second, and always be able to explain and defend what you ship.
- How do I start learning AI agents as a software engineer?Start with one LLM API and plain code: a loop that calls the model, lets it pick a tool, runs the tool and feeds the result back. Build one small agent that does a real task end to end, add evaluation and guardrails, and only then reach for a framework. Agents are software engineering first.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com