🔀

Conditional Generation

Generate contextually appropriate responses based on user attributes.

The Challenge

Different users need different levels of detail, different tone, and different features. Managing this in code means branching logic that obscures the actual prompt content.

The Solution

Use case blocks to define content for each user tier and condition triggers for specific scenarios—all in the prompt itself.

feature_support.prompt
init do
  @version: 1.0
  @major: 1

  params:
    @user_tier: enum[free, pro, enterprise]
    @feature_request: str
    @current_plan_limit: int

end init

case @user_tier do
free: # Free tier restrictions
You are helping a free-tier user.
Keep responses concise (2-3 sentences).
Do not provide advanced configurations.
Mention upgrade option: "Pro users get more detailed responses."

pro: # Pro tier
You are helping a Pro-tier user.
Provide detailed responses with examples.
Include configuration options where relevant.
Suggest advanced optimizations.

enterprise: # Enterprise tier
You are helping an Enterprise customer.
Provide comprehensive solutions.
Include security and compliance considerations.
Offer custom integration support.
end @user_tier

if @feature_request has "limit" do
The user is hitting a limit. Current: @current_plan_limit.
Explain the limit kindly and suggest alternatives.
end @feature_request

case @feature_request type do
api: Focus on API integration details.
sdk: Provide code examples in multiple languages.
docs: Generate reference documentation.
security: Include security best practices and compliance notes.
end @feature_request type

response do
  {
    "tier": "@user_tier",
    "response_type": "feature_support",
    "upgrade_suggested": @user_tier is "free"
  }
end response

Key Benefits

  • Content variations are visible in one place
  • Business logic lives in prompts, not code
  • Response contract tracks which tier was served