Requirements and best practices for building ITS compilers
This guide defines the requirements for implementing a compliant ITS compiler. Requirements are categorized using RFC 2119 keywords:
Compilers MUST validate templates against the base schema before processing:
version
, content
)When loading schemas from the extends
array:
template
fieldCompilation MUST fail if:
The extends
array can contain:
https://example.com/schema.json
./local-schema.json
For better user experience, report which schemas are being loaded.
Compilers may cache remote schemas to improve performance.
Optional security features include:
Instruction types are resolved in this order (highest to lowest):
customInstructionTypes
in the templateextends
arrayextends
arrayWhen a type is defined in multiple schemas, the entire definition is replaced. No property merging occurs.
Compilers should inform users when types are overridden:
INFO: Instruction type overrides detected:
- 'summary' overridden by marketing-types.json (from company-types.json)
- 'list' overridden by customInstructionTypes (from its-standard-types-v1.json)
Replace ${variableName}
references with variable values in:
Handle all JSON-compatible types:
${name}
${count}
${enabled}
${user.name}
${items[0]}
If a variable reference is undefined, compilers MUST either:
${undefined}
)Operator Type | Operators | Example |
---|---|---|
Equality | == , != |
tone == 'professional' |
Comparison | > , < , >= , <= |
count > 5 |
Logical | && , || , ! |
includeA && !includeB |
Membership | in |
type in ['A', 'B', 'C'] |
Conditionals can contain other conditionals in their content arrays.
Invalid expressions should produce helpful error messages.
For each placeholder:
If a template references {property}
but it's not in config:
Type Definition:
{
"instructionTypes": {
"list": {
"template": "<<Replace this placeholder with a list using this user prompt: ([{<{description}>}]). Format requirements: Use {format} formatting with each item on a new line.>>",
"configSchema": {
"type": "object",
"properties": {
"format": {
"type": "string",
"enum": ["bullet_points", "numbered"],
"default": "bullet_points"
}
}
}
}
}
}
Placeholder in Template:
{
"type": "placeholder",
"instructionType": "list",
"config": {
"description": "List 5 fruits",
"format": "bullet_points"
}
}
Processing Steps:
{description}
with "List 5 fruits"{format}
with "bullet_points"([{<List 5 fruits>}])
Generated Instruction:
<<Replace this placeholder with a list using this user prompt: ([{<List 5 fruits>}]). Format requirements: Use bullet_points formatting with each item on a new line.>>
The compiled output must have these sections:
INTRODUCTION
[System prompt from compilerConfig]
INSTRUCTIONS
[Processing instructions from compilerConfig]
TEMPLATE
[Processed template content with instructions]
Maintain line breaks, spacing, and structure from the original template.
Error Type | Required Behavior | Example Message |
---|---|---|
Schema Validation | MUST fail compilation | "Template validation failed: Missing required property 'content'" |
Schema Loading | MUST fail compilation | "Failed to load schema: https://example.com/types.json (404 Not Found)" |
Version Mismatch | MUST fail compilation | "Schema version 2.0 incompatible with template version 1.0" |
Undefined Variable | MUST fail or preserve | "Undefined variable: ${productName}" |
Invalid Expression | MUST fail compilation | "Invalid conditional expression: 'count >> 5'" |
Missing Type | MUST fail compilation | "Unknown instruction type: 'custom_type'" |
Recompile templates when source files change.
Besides the standard prompt format, compilers may generate:
Language server protocol support for real-time validation.
The ITS Compiler Python provides a complete reference implementation of this specification. Use it to:
Installation:
pip install its-compiler-python
Usage:
# Compile a template
its-compile template.json --output prompt.txt
# Validate without compiling
its-compile template.json --validate-only
# Watch mode for development
its-compile template.json --watch
function compileTemplate(templatePath) {
// 1. Load and validate template
const template = loadJSON(templatePath)
validateSchema(template, BASE_SCHEMA)
// 2. Load extended schemas
const types = {}
for (const schemaUrl of template.extends || []) {
const schema = loadSchema(schemaUrl)
validateSchema(schema, TYPE_EXTENSION_SCHEMA)
// Apply overrides
Object.assign(types, schema.instructionTypes)
}
// 3. Apply custom types (highest precedence)
Object.assign(types, template.customInstructionTypes || {})
// 4. Process variables
const processedContent = processVariables(template.content, template.variables)
// 5. Evaluate conditionals
const finalContent = evaluateConditionals(processedContent, template.variables)
// 6. Generate instructions
const compiledTemplate = generateInstructions(finalContent, types)
// 7. Assemble final output
return assembleOutput(template.compilerConfig, compiledTemplate)
}