Overview

Prompt engineering is the design of LLM inputs so the outputs are accurate, structured, and repeatable. Quality of output tracks quality of prompt; vague prompts produce vague answers and brittle workflows. This page consolidates the seven strategies that hold up across enterprise platforms: Palantir Foundry AIP, OpenAI, Microsoft Foundry, and Google Vertex AI all converge on the same rules. The full Palantir guidance is at the Foundry AIP “Best practices for LLM prompt engineering” page; the OpenAI version is at the OpenAI Help Center; the Microsoft version is the Azure OpenAI “Prompt engineering techniques” article; the Google version is the Kaggle “Prompt Engineering” whitepaper by Lee Boonstra.

Be clear and specific

Use straightforward language. State the task or question in the words a domain expert would use. Pin the context that anchors the response.

Bad:  What do you know about coding?
Good: Summarize my framework options for building a static documentation site
      in TypeScript that ships at under 200 KB of JavaScript.

Specifying “as a software engineer” or “as a tax accountant” at the head of the prompt anchors register and depth. See role-priming.

Refine and iterate

A prompt is a first draft. Run it, read the output, identify the failure mode, change one variable, re-run. The fastest feedback loop in software engineering. Keep a prompt history in version control next to the code that calls the model.

When the model misunderstands, the fix is almost always more specificity in the prompt, not more parameters in the call. Start with the simplest prompt that could work and add only what failure modes demand.

Use examples (few-shot)

Show the format you want with one to five worked examples. Few-shot beats zero-shot for any task with structured output, classification, or unusual format. See few-shot-prompting.

Translate each English sentence to French. Example:
English: Hello, how are you?
French: Bonjour, comment allez-vous?

Translate: Where is the train station?

For multi-class classification, include at least one example per class. The model infers the schema from the examples, not the instruction.

Manage length and complexity

Be concise. Provide the details that change the answer; cut the ones that do not. Long prompts add noise and consume context budget that could hold examples or grounding data.

Break complex tasks into ordered sub-tasks. Ask for the steps first, then ask for elaboration. A chain of two narrow prompts produces sharper output than one broad prompt.

Bad:  Explain semiconductor manufacturing.
Good: First, list the major steps in semiconductor manufacturing in order.
      Then explain each step in 2-3 sentences for a software engineer.

Incorporate constraints

State the output shape, length, format, and exclusions explicitly.

Summarize the article in no more than three sentences.
Return only the JSON object; no prose preamble or postamble.
List the pros and cons of remote work. Exclude personal opinions.
Reply with NOT_FOUND if the answer is not in the provided text.

The “out” clause (reply NOT_FOUND if the answer is not present) is the single highest-impact mitigation against fabrication on grounded-Q&A tasks. Always offer the model an explicit escape hatch when the input may not contain the answer.

Provide relevant context

Match the prompt to the model’s strengths and to the grounding data on hand. For models with retrieval-augmented context (RAG), the closer the source material is to the final answer, the less the model has to invent. See rag.

Use a system-message for stable role and policy (“you are a customer-support agent for Contoso pharmacy; do not ask for PII”). Use the user message for the per-turn input. Use clear delimiters (---, ###, XML, or markdown headings) to separate instructions from primary content so the model can tell them apart.

You are a helpful assistant. Summarize the text below as a bulleted list
of the most important points.

Text: """
{paste source text here}
"""

Optimize the interaction

Two patterns are worth knowing by name.

  • Role-playing. Assign a role to anchor tone and depth. “As a mechanical engineer, describe the most important sensors to deploy in a heavy manufacturing process.” See role-priming.
  • Sequential prompting. Chain related turns when one prompt would overload the model. First describe the process. Then list three variants. Then compare them. Each turn carries the work of the previous turn.

For reasoning-sensitive tasks, ask the model to take a step-by-step approach and to cite sources before producing a final answer. The chain-of-thought scaffold reduces hallucination and makes the reasoning auditable. See chain-of-thought.

Tactical rules of thumb

Five patterns to memorize:

  • Put the instruction at the top. Models exhibit recency bias, but starting with the task gives the model a frame for the rest of the prompt. Repeat the instruction at the end for long prompts.
  • Articulate format with examples. “Show, do not tell.” A two-line example of the target output beats a paragraph of prose describing it.
  • Say what to do, not just what to avoid. “Refer the user to /help/faq” beats “do not ask for the password” in instruction-following accuracy.
  • Lower temperature for factual tasks. 0 for extraction and Q&A; 0.7+ only for creative tasks. See temperature.
  • Add citations to the output spec. A model asked to cite its sources fabricates less, because every fabricated claim now requires a fabricated citation that breaks under inspection.

Validate every prompt against an eval set

A prompt is production code. Build a fixed eval set of inputs with known correct outputs and run the prompt against it after every change. Promote a new prompt only when the eval set passes at the threshold the application requires. See prompt-design for the regression-testing pattern and structured-prompt for the structured input shape that makes evals tractable.

Sources

  • Palantir Foundry AIP: “Best practices for LLM prompt engineering”
  • OpenAI Help Center: “Best practices for prompt engineering with the OpenAI API”
  • Microsoft Foundry: “Prompt engineering techniques”
  • Google / Kaggle: “Prompt Engineering” whitepaper by Lee Boonstra
  • Anthropic: “Prompt engineering overview”