Skip to content
Guest
AI Engineering · Course Syllabus Show lessons
LLM Foundations · 9 min read · Intermediate

Structured Prompting, Few-Shot & Constraints

Write clear, testable prompts using role clarity, explicit output rules, few-shot examples, and refusal rules.

What you'll learn

  • Replace vague prompts with explicit acceptance criteria
  • Use 2 to 3 few-shot input/output examples to lock formatting
  • Instruct the model how to say 'I don't know' when context is missing

Overview

Write clear, testable prompts using role clarity, explicit output rules, few-shot examples, and refusal rules.

Code Example

const systemPrompt = `Extract invoice fields from the text.
Rules:
1. Return ONLY valid JSON matching { vendor, totalPhp, date }.
2. If a field is missing, set it to null instead of guessing.`;

Key Takeaways

  • Replace vague prompts with explicit acceptance criteria
  • Use 2 to 3 few-shot input/output examples to lock formatting
  • Instruct the model how to say ‘I don’t know’ when context is missing

Quick Check

Check Your Understanding

Score: 0 / 1

1. What is the most effective way to prevent an LLM from inventing missing fields during data extraction?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind