Skip to main content

Constraints Component

The <Constraints> component defines rules and constraints that guide Claude’s behavior and output format. Constraints are added to the prompt to enforce specific requirements.
Current Implementation: Constraints are serialized into the prompt as a <constraints> element. The constraint text is included in the prompt children and will be visible to Claude. Dedicated constraint enforcement beyond prompt inclusion is planned for a future release.

Usage

import { Constraints } from "smithers-orchestrator";

<Claude>
  <Constraints>
    - Keep responses under 500 words
    - Use bullet points for lists
    - Include code examples where applicable
    - Cite sources when making claims
  </Constraints>

  Explain the SOLID principles.
</Claude>

Props

children
ReactNode
The constraints to apply, typically as a list of rules.

Examples

Output Format Constraints

<Claude>
  <Constraints>
    - Respond in JSON format only
    - Include a "summary" field
    - Include an "issues" array
    - Include a "recommendations" array
  </Constraints>

  Analyze this code for issues.
</Claude>

Behavioral Constraints

<Claude>
  <Constraints>
    - Do not make changes to the database schema
    - Only modify files in the src/components directory
    - Run tests after each change
    - Commit changes with descriptive messages
  </Constraints>

  Refactor the Button component to use CSS modules.
</Claude>

Security Constraints

<Claude>
  <Constraints>
    - Never store plaintext passwords
    - Always sanitize user input
    - Use parameterized queries for database access
    - Log security-relevant events
  </Constraints>

  Implement user authentication.
</Claude>

Quality Constraints

<Claude>
  <Constraints>
    - All functions must have TypeScript types
    - Include JSDoc comments for public APIs
    - Write unit tests for new functionality
    - Follow existing code style
  </Constraints>

  Add a new API endpoint for user profiles.
</Claude>

Combining with Persona

Constraints work well with the <Persona> component:
<Claude>
  <Persona role="security engineer">
    You specialize in application security.
  </Persona>

  <Constraints>
    - Focus on OWASP Top 10 vulnerabilities
    - Prioritize high-severity issues
    - Provide remediation steps for each finding
    - Rate each issue by severity (low/medium/high/critical)
  </Constraints>

  Perform a security audit of the authentication module.
</Claude>

Best Practices

Vague constraints are harder to follow:
// Good - specific and measurable
<Constraints>
  - Keep functions under 50 lines
  - Maximum 3 parameters per function
  - Test coverage must be above 80%
</Constraints>

// Less effective - vague
<Constraints>
  - Write clean code
  - Make it good
</Constraints>
Tell Claude what to do, not just what to avoid:
// Positive framing
<Constraints>
  - Use parameterized queries
  - Validate all user input
  - Return early for error cases
</Constraints>

// Negative framing (sometimes needed)
<Constraints>
  - Do not use string concatenation for SQL
  - Never trust user input
</Constraints>