Overview
Concrete tool for generating example values conforming to JSON schemas, used by prompt templates to help LLMs understand expected output structure.
Description
The JSONSchemaExampleGenerator class recursively generates example values conforming to JSON schemas. Handles strings, integers, numbers, booleans, arrays, and objects with configurable depth and length limits. The module also defines `DEFAULT_SYSTEM_PROMPT`, the default system prompt used by agents when no custom system prompt is provided. Used by `PromptTemplate` to generate output format examples that help LLMs understand expected output structure.
Usage
- Output format examples: Used by `PromptTemplate` to generate conforming examples for LLM output schemas.
- Schema validation: Generate test values that conform to a JSON schema for testing.
- Default prompts: `DEFAULT_SYSTEM_PROMPT` is the fallback system prompt for agents.
Code Reference
Source Location
Signature
class JSONSchemaExampleGenerator:
def generate(self, schema: dict, depth: int = 0) -> Any
# Recursively generates example values conforming to JSON schema
# Handles: strings, integers, numbers, booleans, arrays, objects
DEFAULT_SYSTEM_PROMPT: str # Default agent system prompt
Import
from evoagentx.prompts.utils import JSONSchemaExampleGenerator, DEFAULT_SYSTEM_PROMPT
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| schema |
dict |
Yes |
JSON schema definition
|
| depth |
int |
No |
Nesting depth limit
|
Outputs
| Name |
Type |
Description
|
| generate returns |
Any |
Example value conforming to schema
|
Usage Examples
Generate Schema Example
from evoagentx.prompts.utils import JSONSchemaExampleGenerator
generator = JSONSchemaExampleGenerator()
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
}
}
example = generator.generate(schema)
# Returns: {"name": "example_string", "age": 42}
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.