Processing Order
Sequential information generation is a critical capability for creating structured and coherent content, especially in complex scenarios where the context and dependency of information are paramount. Utilizing a defined ProcessingOrder in the schema ensures that the generation process follows a logical sequence, building up information step-by-step.
Example: Chapter Definition
Let's consider the following schema for a chapter in a book:
- Go
- Python
- JavaScript
// jsonSchema.Definition for Chapter
chapterDefinition := jsonSchema.Definition{
Type: jsonSchema.Object,
Instruction: "Create the details of the chapter so that the story being written will feel real and lived in.",
Model: jsonSchema.ClaudeSonnet,
ProcessingOrder: []string{"title", "outline", "pages"},
Properties: map[string]jsonSchema.Definition{
"title": {
Type: jsonSchema.String,
Instruction: "Create a title for the chapter which must be less than 5 words.",
},
"outline": {
Type: jsonSchema.String,
Instruction: fmt.Sprintf("Create an outline of what will occur in this chapter. Return a minimum of 100 words for this outline. This outline should cover what will occur in %d pages", pageNum),
},
"pages": {
Type: jsonSchema.Array,
Instruction: fmt.Sprintf("Create a list of %d pages, where each page outline should be detailed enough to ensure that each one logically leads to the next, creating a satisfying narrative progression. Return a maximum of %d items.", pageNum, pageNum),
Items: &pageDefinition,
},
},
}
# Definition for Chapter
chapter_definition = Definition(
definition_type="object",
instruction="Create the details of the chapter so that the story being written will feel real and lived in.",
model="claude-sonnet",
processing_order=["title", "outline", "pages"],
properties={
"title": Definition(
definition_type="string",
instruction="Create a title for the chapter which must be less than 5 words."
),
"outline": Definition(
definition_type="string",
instruction=f"Create an outline of what will occur in this chapter. Return a minimum of 100 words for this outline. This outline should cover what will occur in {page_num} pages"
),
"pages": Definition(
definition_type="array",
instruction=f"Create a list of {page_num} pages, where each page outline should be detailed enough to ensure that each one logically leads to the next, creating a satisfying narrative progression. Return a maximum of {page_num} items.",
items=page_definition
)
}
)
// Definition for Chapter
const chapterDefinition = {
type: "object",
instruction: "Create the details of the chapter so that the story being written will feel real and lived in.",
model: "claude-sonnet",
processingOrder: ["title", "outline", "pages"],
properties: {
title: {
type: "string",
instruction: "Create a title for the chapter which must be less than 5 words."
},
outline: {
type: "string",
instruction: `Create an outline of what will occur in this chapter. Return a minimum of 100 words for this outline. This outline should cover what will occur in ${pageNum} pages`
},
pages: {
type: "array",
instruction: `Create a list of ${pageNum} pages, where each page outline should be detailed enough to ensure that each one logically leads to the next, creating a satisfying narrative progression. Return a maximum of ${pageNum} items.`,
items: pageDefinition
}
}
};
How Processing Order Works
processingOrder defines the sequence in which fields are generated. This ensures fields are created before they're referenced by later fields using selectFields.
Important: Processing order controls generation sequence, not context passing. To include data from earlier fields in later prompts, use selectFields.
Benefits of Sequential Generation
1. Controlled Dependencies
Generate fields in a specific order to ensure data is available when needed. In the chapter example, title generates first, then outline, then pages—each building on what came before.
2. Logical Information Flow
Sequential generation creates coherent narratives where each piece of data builds naturally on the previous one. The title sets the theme, the outline establishes structure, and pages develop the full content.
3. Complex Structure Support
Handle nested objects and arrays by generating parent structures before children. This prevents missing data references and ensures complete object assembly.
4. Predictable Execution
Explicit ordering removes ambiguity about field generation sequence, making schemas easier to understand, debug, and maintain.
5. Foundation for SelectFields
Processing order ensures fields exist before they're referenced. Combine with selectFields to pass specific data between generation steps.