Prompt Engineering

What is prompt engineering and why does it matter?


  • A prompt is the instructions and context supplied to a generative AI model; prompt engineering is designing and testing those inputs to obtain useful, reliable outputs.
  • It is usually the quickest and cheapest first step for improving an LLM application because it does not require retraining the model.
  • Prompts are model-dependent: wording, supported features and results can vary by model and version. Test prompts on representative questions rather than assuming one successful response proves reliability.
  • A system prompt sets overarching behaviour; a user prompt supplies the immediate request. In applications, retrieved documents and tool results can add further context.

How do you write a clear and effective prompt?


  • State the task, audience, relevant context, constraints and desired output format explicitly.
  • Use delimiters such as triple backticks or XML-style markers to separate source material from instructions; tell the model to treat quoted documents as data, not instructions.
  • Specify a structured output when needed, such as JSON with named keys or a Markdown table. For machine processing, prefer a model’s supported structured-output or schema enforcement feature where available.
  • Include a few representative input/output examples (few-shot prompting) to demonstrate the expected style, classifications or format.
  • Define how to handle missing information: instruct the model to say it cannot determine an answer, identify uncertainty, or ask a clarifying question rather than inventing details.
  • For complex tasks, ask for a concise explanation of assumptions and a checked final answer; requesting hidden step-by-step reasoning is not necessary to get useful results.
  • Example reusable template:
You are a customer-support assistant.
Answer only using the reference material below.
If the answer is not supported, say "I don't know based on the provided information."
Do not invent people, dates, policies or product details.

<reference>
[Insert trusted source text]
</reference>

Question: [Insert question]
Return: A short answer followed by the supporting source passage.

How do you test hallucinations in Databricks AI Playground?


  • Open AI/ML → AI Playground (navigation may vary) and choose an available chat model; the lesson uses GPT OSS 120B.
  • Test 1 — induce a hallucination: Use an intentionally permissive system instruction encouraging an invented biography, then ask about a fictional or nonexistent person. Observe whether the model presents invented details as facts. This is a controlled demonstration, not a production prompt.
  • Test 2 — discourage fabrication: Clear the chat history, replace the system instruction with Only state facts supported by the information provided. If you cannot verify an answer, say you don't know. Do not invent biographical details., and repeat the question.
  • Compare outputs: the second prompt should encourage uncertainty rather than invention, but prompting cannot guarantee that hallucinations never occur.
  • Clear or start a new conversation between tests to prevent previous turns from affecting the comparison. Keep model and question constant when testing the effect of one prompt change.
  • Optionally compare two available models side by side to see whether they interpret the same instructions differently.

When is prompting sufficient, and when do you need more?


  • Use prompt engineering for tone, output structure, simple classification, extraction and behaviour when the model already has enough relevant context.
  • Use RAG when answers require private company information, current documents, product specifications or other facts absent from the model’s training context.
  • Use tools/function calling when the system must perform actions, query live systems or calculate from authoritative data rather than merely describe something.
  • Consider fine-tuning for repeatable task-specific behaviour or format improvements after establishing prompt and evaluation baselines; it is not a substitute for retrieving changing facts.
  • Evaluate using realistic test questions, including ambiguous queries, missing evidence, conflicting documents and attempts to override instructions. Track factual accuracy, completeness, format adherence, latency and cost.

Where can you read more?