12 min readLLMPromptingIA
Table of contents
  1. Chain-of-thought prompting
  2. Few-shot learning
  3. Structured output (JSON mode)
  4. Combining techniques

Chain-of-thought prompting

Chain-of-thought is a technique that involves asking the model to break down its reasoning step by step before giving the final answer. The effect is striking on complex tasks: errors decrease significantly because the model "thinks out loud" instead of short-circuiting to an intuitive response.

How to activate it: simply add "Reason step by step before answering." or "Let's think through this methodically: ..." to your prompt.

Ideal use cases: solving logic problems, debugging code, analyzing arguments, estimating costs, project planning.

When to avoid it: simple or factual tasks where chain-of-thought unnecessarily lengthens the response without adding value.

Few-shot learning

Few-shot learning involves providing a few input/output examples in the prompt to show the model exactly what you expect. It's one of the most effective techniques for controlling output format.

Example:

Classify the sentiment of the following sentences:
"This product is excellent." → Positive
"I'm very disappointed." → Negative
"It's fine, neither good nor bad." → Neutral
"Never seen anything so effective!" → ?

The model immediately understands the expected format — a single label — and produces a consistent response. With zero-shot (no examples), responses vary more in format and verbosity.

Rule of thumb: 2 to 5 examples are sufficient in most cases. Beyond that, the gain is marginal and you consume context unnecessarily.

Structured output (JSON mode)

Most advanced models support a JSON mode that guarantees parseable output. This is essential for applications that need to process model responses programmatically.

Without JSON mode, even asking "Reply in JSON" can result in the model adding text before or after, or using different quote styles. With JSON mode activated via the API, the output is always valid.

Going further, some models support JSON schema constraints (Structured Outputs at OpenAI, or via tools like Instructor or Outlines). You define the exact expected schema and the model cannot deviate.

Example prompt for JSON: "Extract the following information from the text and return it as JSON with keys: name, email, company, role. Text: [your text]".

Combining techniques

These techniques are not exclusive — they combine. An expert prompt can simultaneously use:

- A role ("You are a senior financial analyst.")
- Context (the data to analyze)
- Examples (2-3 similar analyses)
- A chain-of-thought instruction ("Reason step by step")
- A format constraint (markdown table or JSON)

The risk is overloading the prompt and drowning out important instructions. Start simple, measure the result, then add one technique at a time until you get the desired behavior.

The most useful discipline in prompt engineering: document your prompts that work. An effective prompt is a reusable asset.

Share: