LLMs & Generative AI

Prompting & Decoding

Prompting defines task, context, constraints, and examples; decoding controls how the model chooses output tokens through settings such as temperature and top-p.
  • A prompt is an interface contract
  • Examples beat vague style instructions
  • Temperature controls randomness
  • Top-p limits sampling to a probability mass
  • Prompt changes are code changes
Prompt skeleton for extraction
Task: Extract invoice fields from the text.
Rules:
- Use only values explicitly present in the document.
- Return JSON only.
- Use null for missing fields.
- Do not guess.
Schema:
{ "invoiceNumber": string|null, "amount": number|null, "currency": string|null }
Document:
<text here>
Make uncertainty and output shape explicit.
Decoding controls
SettingLower valueHigher value
TemperatureMore deterministicMore varied / creative
Top-pSmaller candidate poolBroader candidate pool
Max tokensShorter output / cheaperMore complete / costlier
Sources
  • Claude Prompt Engineering and Evaluation DocsPrompt engineering overview
  • OpenAI API DocumentationPrompting and text generation
  • Hugging Face LLM CourseInference with LLMs