Basic prompting techniques
Welcome to Practical Prompt Engineering! Imagine asking a friend to plan your weekend trip. If you just say "plan a trip," you get a vague answer. But if you say "plan a 2-day trip to Napa Valley focused on wine tasting for two adults on a $500 budget", you get exactly what you need. Prompting LLMs works the same way.
Prompt structure
The building blocks of an effective prompt
You do not need to label them with headers. The model picks up on structure naturally. What matters is that all three elements are present in your prompt. Labels can help when prompts get long, but for shorter prompts, just include the information in a clear order.
Every effective prompt has three parts: Context (background info the model needs), Task (what you want it to do), and Format (how you want the output). Here is a basic prompt vs. a structured one: Bad: "Tell me about Napa Valley" Good: "You are a travel planner. Create a 2-day Napa Valley itinerary for wine lovers. Format it as a numbered list with times, activities, and estimated costs."
temperature=0.0 means deterministic output where the model always picks the most likely next token, producing consistent results. Higher temperature (e.g. 0.8) adds randomness for creative tasks. For prompt engineering experiments, start at 0.0 so results are reproducible.
from litellm import completion
import os
MODEL_NAME = os.getenv("MODEL_NAME", "gemini/gemini-2.5-flash")
def get_completion(prompt, system_prompt=None, temperature=0.0):
messages = []
if system_prompt:
messages.append({"role": "system", "content": system_prompt})
messages.append({"role": "user", "content": prompt})
response = completion(model=MODEL_NAME, messages=messages,
temperature=temperature, max_tokens=1024)
return response.choices[0].message.content
# Vague prompt
print(get_completion("Tell me about Napa Valley"))
# Structured prompt with Context + Task + Format
prompt = """You are a travel planner for wine enthusiasts.
Create a 2-day Napa Valley itinerary.
Format: numbered list with time, activity, and cost."""
print(get_completion(prompt))The get_completion() helper wraps LiteLLM so you can focus on the prompt itself. Notice how adding Context, Task, and Format to the prompt produces a much more useful response.
For simple tasks like "translate hello to French," the Task alone is enough. But as prompts get complex, adding Context and Format prevents the model from guessing what you want. Think of it as a spectrum: simple questions need less structure, but production prompts almost always benefit from all three parts.
AI prompt: Try it with AI
Loading practice…
Matching exercise: Match the prompt part
Loading practice…
Fill in the blanks: Complete the structured prompt
Loading practice…
Flashcards: Flashcards
Loading practice…
Validation checklist: Basic prompting checklist
Loading practice…