# Dynamic Scaffolding

> Inject task-specific scaffolding (examples, hints, schemas) into the prompt only when the task type warrants it.

- **Category**: Agentic AI
- **Subcategory**: Routing & Composition
- **Canonical URL**: https://designpattern.fyi/patterns/dynamic_scaffolding/

---

## Description
**Intent**: Inject task-specific scaffolding (examples, hints, schemas) into the prompt only when the task type warrants it.
**Context**: A general-purpose agent handles a wide range of task types in one product — answering free-text questions, writing or refactoring code, querying databases, transforming structured documents. Some of those tasks benefit a lot from extra material in the prompt such as worked examples, output schemas, or domain hints, while others are trivial and need none of it. The same prompt is shared across every request unless the team does something about it.
**Solution**: Maintain a library of scaffolds (few-shot examples, schemas, hints) keyed by task type or feature. At runtime, classify the task and inject the matching scaffolds. Audit which scaffolds fired per request.


## Use Cases
- Some tasks need few-shot examples, schemas, or hints and others do not — static prompts overshoot or undershoot.
- A library of scaffolds keyed by task type or feature can be maintained.
- Task classification at runtime is reliable enough to route the right scaffold.





## Trade-offs


### Advantages

- Token efficiency.

- Targeted quality lift on hard cases.




### Considerations & Drawbacks

- Scaffold library maintenance.

- Misclassification injects wrong scaffolds.







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/dynamic-scaffolding/)

