Skip to main content

Decision Trees & Scoring

Use decision points to route generation based on scoring criteria. This enables quality control, content refinement, and conditional logic flows.

Overview​

Decision trees allow you to:

  • Score generated content against multiple dimensions
  • Branch conditionally based on score thresholds
  • Refine outputs that don't meet quality criteria
  • Route to different workflows based on content characteristics

Blog Post Quality Router Example​

This example generates a technical blog post, scores it for technical accuracy and readability, and refines it if needed:

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": "number"
},
"readability": {
"description": "Rate the readability from 0-100",
"type": "number"
}
}
},
"decisionPoint": {
"name": "ContentQualityRouter",
"branches": [
{
"name": "HighAccuracyLowReadability",
"conditions": [
{
"field": "technical_accuracy",
"operator": "gt",
"number_value": 95
},
{
"field": "readability",
"operator": "lt",
"number_value": 95
}
],
"then": {
"type": "object",
"instruction": "Improve readability while maintaining technical accuracy",
"selectFields": ["content"],
"properties": {
"simplified_content": {
"type": "string",
"instruction": "Simplify the language"
}
}
}
}
]
}
}
}
}
}'

Decision Point Components​

Scoring Criteria​

Define multiple dimensions to evaluate the generated content:

"scoringCriteria": {
"dimensions": {
"dimension_name": {
"description": "Clear description of what to evaluate (0-100)",
"type": "number"
}
}
}

Decision Point Structure​

FieldTypeDescription
namestringIdentifier for the decision point
branchesarrayList of conditional branches to evaluate

Branch Configuration​

FieldTypeDescription
namestringBranch identifier
conditionsarrayList of conditions (AND logic)
thenobjectSchema to execute if conditions match

Condition Operators​

OperatorDescription
gtGreater than
ltLess than
gteGreater than or equal
lteLess than or equal
eqEqual to
neNot equal to

Expected Response​

The response follows the gRPC structure with nested fields:

{
"data": {
"fields": {
"content": {
"string_value": "Microservices: Building Blocks for Scalable and Resilient Applications\n\nMicroservices architecture has emerged as a popular approach to building complex applications. Instead of a monolithic application, microservices structure an application as a collection of small, autonomous services, modeled around a business domain..."
},
"simplified_content": {
"string_value": "Microservices: Small, independent services that work together to form an application. They each own their data, communicate over a network, and can be deployed independently.\n\nBenefits include better scaling, faster development, improved resilience, technology flexibility, and easier maintenance..."
}
}
},
"usdCost": 0
}

Response Structure​

  • data.fields: Contains all generated fields
  • Each field has a string_value property containing the generated content
  • usdCost: The cost of the generation in USD (when applicable)

Use Cases​

  1. Content Quality Control: Score and refine generated content
  2. Multi-path Workflows: Route based on content characteristics
  3. Iterative Refinement: Automatically improve outputs that don't meet thresholds
  4. A/B Testing: Generate multiple variants based on scoring
  5. Compliance Checking: Validate generated content meets requirements

Best Practices​

  1. Clear Scoring Criteria: Be specific about what each dimension measures
  2. Reasonable Thresholds: Set achievable score thresholds (70-80 is often good)
  3. Multiple Dimensions: Use 2-4 dimensions for nuanced evaluation
  4. Actionable Branches: Make branch actions specific and targeted
  5. Use selectFields: Pass relevant context to branch schemas
tip

Decision points can be nested! You can have a decision point in a branch's then schema for multi-stage refinement.

Next Steps​