Modular Prompting Pattern

Definition

Decomposing complex prompts into reusable, composable modules that can be assembled for different tasks. Treating prompt engineering like software engineering, with components, interfaces, and composition.

Components

System Context: Role definition, constraints, style guidelines Task Specification: What the model should do Input Format: How data will be provided Output Format: Expected structure of response Examples: Few-shot demonstrations Guardrails: Safety constraints, edge case handling

Benefits

  • Reusability: Core modules work across tasks
  • Testability: Individual modules can be validated
  • Maintainability: Change one module without rewriting everything
  • Versioning: Track prompt changes like code changes

Composition Patterns

Sequential: Module A output feeds Module B Parallel: Multiple modules process same input Conditional: Different modules for different input types Iterative: Module output refines own input

Anti-Patterns

  • Monolithic prompts that do everything
  • Copy-paste prompt fragments without understanding
  • No separation between task logic and formatting
  • Implicit assumptions buried in prose

Related: 00-source—schulhoff-2024-prompt-report, 05-molecule—chain-of-thought-prompting