Soft Constraints

Soft constraints are flexible guidelines in prompts that AI should follow when possible but can deviate from when necessary. Unlike hard constraints (must/must not), soft constraints use language like 'prefer', 'typically', or 'when possible' — giving AI judgment latitude.

Example

'Prefer functional components over class components, but use classes if the library requires it.' The preference is clear, but AI can override when the situation demands.

Soft constraints give you the benefits of guidance without the rigidity of absolute rules. They communicate preferences while allowing AI to exercise judgment.

Hard vs Soft Constraints

Hard ConstraintsSoft Constraints
"Must validate inputs""Prefer early returns"
"Never use any type""Typically under 50 lines"
"Always handle errors""When possible, use named exports"
No flexibilityJudgment allowed

When to Use Soft Constraints

Style preferences:

  • Naming conventions with exceptions
  • Code organization patterns
  • Comment frequency

Situational guidance:

  • "Prefer X unless Y"
  • "Typically do X, but Z is acceptable"
  • "When possible, follow X"

Quality targets:

  • Function length guidelines
  • Complexity thresholds
  • Performance considerations

Writing Effective Soft Constraints

Clear preference: "Prefer composition over inheritance"

With exception: "Prefer functional components, unless state management requires class lifecycle methods"

With reasoning: "Typically keep functions under 30 lines (for readability), but prioritize clarity over length"

Soft Constraints in Cursor Rules

# Soft Constraints
- Prefer named exports over default exports
- Typically use TypeScript strict mode
- When possible, colocate tests with source files
- Generally avoid comments for obvious code

Balancing Hard and Soft

  • Use hard constraints for non-negotiables (security, correctness)
  • Use soft constraints for preferences (style, organization)
  • Too many hard constraints = rigid, unnatural code
  • Too many soft constraints = inconsistent output

The right mix gives AI enough guidance to be helpful while enough freedom to be intelligent.