Skip to main content

Recursive Decision Points

Create multi-level quality control workflows by nesting decision points within branches. This enables iterative refinement, progressive quality checks, and complex routing logic.

Overview

Recursive decision points allow you to:

  • Iteratively refine content until quality thresholds are met
  • Chain multiple quality checks with fallback handling
  • Create progressive improvement workflows with multiple attempts
  • Handle edge cases with default branches
  • Build sophisticated routing logic with nested conditions

Multi-Level Content Refinement Example

This real-world example demonstrates recursive decision points for content quality control with multiple refinement stages:

curl -X POST http://localhost:2008/objectGen \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"prompt": "Generate a technical blog post about microservices architecture and best practices",
"definition": {
"type": "object",
"properties": {
"content": {
"type": "string",
"instruction": "Generate a technical blog post about microservices",
"scoringCriteria": {
"dimensions": {
"technical_accuracy": {
"description": "Rate the technical accuracy from 0-100",
"type": "numeric"
},
"readability": {
"description": "Rate the readability from 0-100",
"type": "numeric"
},
"completeness": {
"description": "Rate the completeness of the content from 0-100",
"type": "numeric"
}
}
},
"decisionPoint": {
"name": "ContentQualityRouter",
"branches": [
{
"name": "HighQuality",
"conditions": [
{
"field": "technical_accuracy",
"operator": "gte",
"number_value": 90
},
{
"field": "readability",
"operator": "gte",
"number_value": 90
},
{
"field": "completeness",
"operator": "gte",
"number_value": 90
}
],
"then": {
"type": "object",
"instruction": "Content meets quality standards, finalize it",
"selectFields": ["content"],
"properties": {
"final_content": {
"type": "string",
"instruction": "Return the final polished content"
},
"quality_summary": {
"type": "string",
"instruction": "Provide a brief summary of the quality metrics"
}
}
}
},
{
"name": "LowReadability",
"conditions": [
{
"field": "readability",
"operator": "lt",
"number_value": 90
},
{
"field": "technical_accuracy",
"operator": "gte",
"number_value": 80
}
],
"then": {
"type": "object",
"instruction": "Improve readability while maintaining technical accuracy",
"selectFields": ["content"],
"properties": {
"improved_content": {
"type": "string",
"instruction": "Rewrite the content with simpler language",
"scoringCriteria": {
"dimensions": {
"technical_accuracy": {
"description": "Rate the technical accuracy from 0-100",
"type": "numeric"
},
"readability": {
"description": "Rate the readability from 0-100",
"type": "numeric"
},
"completeness": {
"description": "Rate the completeness from 0-100",
"type": "numeric"
}
}
},
"decisionPoint": {
"name": "RecursiveQualityCheck",
"branches": [
{
"name": "MeetsStandards",
"conditions": [
{
"field": "readability",
"operator": "gte",
"number_value": 90
}
],
"then": {
"type": "object",
"instruction": "Finalize the improved content",
"selectFields": ["improved_content"],
"properties": {
"final_content": {
"type": "string",
"instruction": "Return the final content"
}
}
}
}
],
"default": {
"type": "object",
"instruction": "Accept current version",
"selectFields": ["improved_content"],
"properties": {
"fallback_content": {
"type": "string",
"instruction": "Return the content as-is"
}
}
}
}
}
}
}
}
],
"default": {
"type": "object",
"instruction": "Handle edge cases",
"selectFields": ["content"],
"properties": {
"fallback_content": {
"type": "string",
"instruction": "Return the original content"
}
}
}
}
}
}
}
}'

Expected Response

The response shows the result after the content went through the recursive quality checks:

{
"data": {
"fields": {
"content": {
"string_value": "Microservices: A Practical Guide to Building Scalable and Resilient Applications\n\nMicroservices architecture has emerged as a popular approach for building complex and scalable applications..."
},
"final_content": {
"string_value": "Microservices: A Practical Guide to Building Scalable and Resilient Applications\n\nMicroservices architecture has emerged as a popular approach for building complex and scalable applications..."
},
"quality_summary": {
"string_value": "The content is well-written, comprehensive, and provides a balanced view of microservices, covering both benefits and challenges. The best practices section is particularly valuable."
}
}
}
}

Response Flow

  1. Initial Generation: Creates content field
  2. First Decision Point: Scores the content (technical_accuracy, readability, completeness)
  3. Branch Execution: If HighQuality conditions met → generates final_content and quality_summary
  4. Recursive Path: If quality is insufficient → generates improved_content with its own decision point
  5. Nested Decision: The improved_content is scored again and routed through RecursiveQualityCheck
  6. Final Output: Returns the best version based on quality thresholds

Recursive Decision Point Pattern

The key to recursive decision points is nesting decisionPoint within branch then properties:

{
"decisionPoint": {
"name": "FirstLevel",
"branches": [
{
"name": "NeedsWork",
"conditions": [...],
"then": {
"type": "object",
"properties": {
"improved_version": {
"type": "string",
"scoringCriteria": { ... },
"decisionPoint": {
"name": "SecondLevel",
"branches": [
{
"name": "Acceptable",
"conditions": [...],
"then": {
// Final output
}
}
],
"default": {
// Fallback handling
}
}
}
}
}
}
]
}
}

Key Features

1. Default Branches

Handle edge cases and unexpected scenarios:

"default": {
"type": "object",
"instruction": "Handle cases that don't match any branch",
"selectFields": ["content"],
"properties": {
"fallback_content": {
"type": "string",
"instruction": "Return the content with minimal modifications"
}
}
}

2. Multiple Recursion Levels

Your example demonstrates up to 3 levels of nested decision points:

  • Level 1: ContentQualityRouter (checks initial quality)
  • Level 2: RecursiveQualityCheck (re-checks improved content)
  • Level 3: FinalQualityCheck (last attempt with lower thresholds)

3. Progressive Threshold Relaxation

Notice how thresholds can be adjusted at each level:

  • First check: Requires ≥90 for all metrics
  • Second check: Requires ≥90 readability (after improvement)
  • Final check: Accepts ≥85 (more lenient)

Use Cases

  1. Content Quality Control: Iteratively refine until quality standards are met
  2. Code Review Workflows: Multiple review stages with different criteria
  3. Data Validation: Progressive validation with fallback handling
  4. Translation Quality: Refine translations through multiple passes
  5. Compliance Checking: Multi-stage approval workflows
  6. A/B Testing: Generate variants and select best performer

Best Practices

  1. Limit Recursion Depth: Keep to 2-3 levels maximum to avoid excessive token usage
  2. Always Include Default: Handle edge cases gracefully
  3. Use selectFields: Pass relevant context to nested branches
  4. Progressive Thresholds: Relax criteria at deeper levels
  5. Clear Naming: Use descriptive names for decision points and branches
  6. Score Consistently: Use same dimensions across recursion levels
  7. Prevent Infinite Loops: Ensure decreasing thresholds or iteration limits
tip

Use selectFields to pass only the relevant content to nested branches. This reduces token usage and keeps the context focused.

Token Usage

Deep recursion (3+ levels) with multiple branches can significantly increase token usage. Monitor costs and set reasonable recursion limits.

Advanced: Multi-Path Recursion

Your full example shows multiple recursive paths:

ContentQualityRouter
├── HighQuality → final_content
├── LowReadability → improved_content
│ └── RecursiveQualityCheck
│ ├── MeetsStandards → final_content
│ └── NeedsMoreWork → refined_content
│ └── FinalQualityCheck
│ └── Acceptable → final_content
├── LowAccuracy → corrected_content
│ └── AccuracyRecheck
│ └── ImprovedAccuracy → final_content
└── LowCompleteness → expanded_content
└── CompletenessRecheck
└── NowComplete → final_content

Each path handles a specific quality issue and recursively refines until acceptable.

Next Steps