Tips > AI & LLM Integration

Use Few-Shot Prompting for Consistent Output Formatting

When you need the LLM to follow a specific, non-obvious output format, abstract instructions alone are often not enough.

When you need the LLM to follow a specific, non-obvious output format, abstract instructions alone are often not enough. Including 2-3 concrete examples (few-shot prompting) in your system prompt dramatically improves format consistency and reduces parsing failures.

Real-world example: A workflow extracts structured event data from free-text calendar entries. Without examples, the model inconsistently formats times, handles multi-day events differently, and sometimes omits fields.

System prompt with few-shot examples:

Extract event details from the text and return a JSON object.

Example 1:
Input: "Team lunch at Olive Garden next Tuesday from noon to 1:30pm"
Output: {"title":"Team Lunch","location":"Olive Garden","start_date":"next Tuesday","start_time":"12:00","end_time":"13:30","duration_minutes":90,"is_all_day":false}

Example 2:
Input: "Company offsite Dec 15-17 at the Marriott downtown"
Output: {"title":"Company Offsite","location":"Marriott Downtown","start_date":"Dec 15","end_date":"Dec 17","start_time":null,"end_time":null,"duration_minutes":null,"is_all_day":true}

Example 3:
Input: "Quick sync with Sarah tomorrow at 3"
Output: {"title":"Sync with Sarah","location":null,"start_date":"tomorrow","start_time":"15:00","end_time":"15:30","duration_minutes":30,"is_all_day":false}

Now extract from this input:
{{ $json.calendar_text }}
```text
Key patterns demonstrated by the examples:

```text
- Time normalization: "noon" → "12:00", "3" → "15:00"
- Default duration: 30 minutes when no end time specified
- Multi-day handling: start_date/end_date with is_all_day: true
- Null fields: explicitly null instead of omitted
- Title cleaning: removed filler words, proper capitalization
```text
> **Note: Example Selection Matters**
>
> Choose examples that cover your most common edge cases. If 30% of your inputs are multi-day events, at least one example should demonstrate that format. If ambiguous times are common, show how you want them resolved.

Few-shot prompting typically reduces output format errors from ~15-20% to under 3%, which directly translates to fewer failed workflow executions.

**Related:** [Use Manual Trigger During Development Instead of Webhook or Schedule](../api-cost-optimization/01-use-manual-trigger-during-development-instead-of-webhook-or-schedule.md) | [Flatten Deeply Nested API Responses](../code-node-mastery/01-flatten-deeply-nested-api-responses.md)

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

191 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book a 20-minute call