ITS Specification

Complete technical specification for Instruction Template Specification v1.0

Overview

The Instruction Template Specification (ITS) defines a JSON-based format for creating templates that compile into AI instructions rather than static content. This enables content creators to build reusable templates with placeholders that generate dynamic, AI-powered content.

Core Concepts

Schema Structure

Base Schema URL

https://alexanderparker.github.io/instruction-template-specification/schema/v1.0/its-base-schema-v1.json

Required Properties

Property Type Description
version string Template format version (semantic versioning)
content array Array of content elements (text, placeholders, conditionals)

Optional Properties

Property Type Description
extends array Schema references for instruction type definitions (URLs or relative paths)
metadata object Template metadata (name, author, tags, etc.)
customInstructionTypes object Template-specific instruction type definitions
compilerConfig object Configuration for template compilation
variables object Template-level variables for reuse

Content Elements

Text Element

Static text content that appears as-is in the compiled template.

{
  "type": "text",
  "text": "Your static content here",
  "id": "optional-identifier"
}

Instruction Placeholder

Placeholder that becomes an AI instruction in the compiled template.

{
  "type": "placeholder",
  "id": "unique-identifier",
  "instructionType": "list",
  "config": {
    "description": "Content description for the AI",
    "displayName": "Human-readable name",
    // Additional type-specific configuration
  }
}

Conditional Element

Content that appears based on conditions. Conditions can include variables, literals, and expressions.

{
  "type": "conditional",
  "condition": "audienceLevel == 'technical'",
  "content": [
    // Content if condition is true
  ],
  "else": [
    // Content if condition is false (optional)
  ]
}

Variables and Expressions

Variable Definition

Variables are defined in the top-level variables object and can store strings, numbers, booleans, objects, or arrays.

{
  "variables": {
    "tone": "professional",
    "productType": "gaming headset",
    "featureCount": 5,
    "includeSpecs": true,
    "brandInfo": {
      "name": "TechCorp",
      "tagline": "Innovation First"
    }
  }
}

Variable Reference Syntax

Use ${variableName} syntax to reference variables throughout your template:

In Text Elements:

{
  "type": "text",
  "text": "Welcome to ${brandInfo.name} - ${brandInfo.tagline}"
}

In Placeholder Configurations:

{
  "type": "placeholder",
  "instructionType": "list",
  "config": {
    "description": "List ${featureCount} key features of a ${productType}",
    "format": "bullet_points",
    "itemCount": "${featureCount}"
  }
}

Variable Types

Type Example Access Method
String "professional" ${variableName}
Number 42 ${variableName}
Boolean true ${variableName}
Object {"name": "value"} ${object.property}
Array ["item1", "item2"] ${array[0]}

Conditional Expressions

Conditional elements use JavaScript-like expression syntax to control content inclusion:

Supported Operators

Expression Examples

// Simple equality
"condition": "tone == 'professional'"

// Numeric comparison
"condition": "featureCount > 3"

// Boolean check
"condition": "includeSpecs == true"

// Compound conditions
"condition": "tone == 'professional' && featureCount > 3"

// Membership test
"condition": "productType in ['headset', 'speakers', 'microphone']"

// Object property access
"condition": "sections.intro == true"

// Negation
"condition": "!includeSpecs"

Standard Instruction Types

Reference: Standard Types Schema

title

Generates titles and headlines with customizable style and length.

{
  "instructionType": "title",
  "config": {
    "description": "Create a catchy product headline",
    "style": "headline",    // headline, descriptive, catchy, formal, creative
    "length": "short"       // short, medium, long
  }
}

list

Generates formatted lists with customizable styling and item counts.

{
  "instructionType": "list",
  "config": {
    "description": "list 5 different citrus fruits",
    "format": "bullet_points",  // bullet_points, numbered, dashes, plain
    "itemCount": 5              // optional
  }
}

paragraph

Generates paragraphs with specified tone and length.

{
  "instructionType": "paragraph",
  "config": {
    "description": "Write about sustainable technology",
    "tone": "professional",     // formal, casual, enthusiastic, professional, friendly
    "length": "medium"          // short, medium, long
  }
}

table

Generates tables with configurable formatting and dimensions.

{
  "instructionType": "table",
  "config": {
    "description": "Compare technology features",
    "format": "markdown",       // markdown, plain_text, csv
    "columns": 3,               // optional
    "rows": 4                   // optional
  }
}

code_block

Generates code snippets with syntax highlighting.

{
  "instructionType": "code_block",
  "config": {
    "description": "Create a Python function that sorts a list",
    "language": "python"        // javascript, python, java, html, css, sql, bash, generic
  }
}

dialogue

Generates conversations between multiple participants.

{
  "instructionType": "dialogue",
  "config": {
    "description": "Conversation about project planning",
    "participantCount": 2,      // 2-6
    "style": "casual"           // casual, formal, dramatic, humorous
  }
}

quote

Generates relevant quotes with optional attribution.

{
  "instructionType": "quote",
  "config": {
    "description": "Quote about innovation and creativity",
    "includeAttribution": true  // include attribution if true
  }
}

summary

Generates summaries of varying lengths and detail.

{
  "instructionType": "summary",
  "config": {
    "description": "Summarize the key benefits of renewable energy",
    "length": "standard"        // brief, standard, detailed
  }
}

image_description

Generates descriptive text for images with different styles.

{
  "instructionType": "image_description",
  "config": {
    "description": "Describe a futuristic city skyline",
    "style": "photorealistic"  // photorealistic, artistic, technical
  }
}

Schema Extension Mechanism

Overview

Templates can import instruction type definitions from external schemas using the extends property. This enables sharing and reusing instruction types across templates.

{
  "$schema": "https://alexanderparker.github.io/.../its-base-schema-v1.json",
  "version": "1.0.0",
  "extends": [
    "https://alexanderparker.github.io/.../its-standard-types-v1.json",
    "./my-local-types.json",
    "https://example.com/custom-types.json"
  ],
  "content": [...]
}

Resolution Rules

1. Complete Override Principle

When multiple schemas define the same instruction type, the entire definition from the later schema replaces the earlier one. No partial merging occurs.

Example: If both schema1.json and schema2.json define a "summary" type, and you extend [schema1, schema2], only schema2's definition is used.

2. Precedence Order

Instruction types are resolved in this order (highest to lowest precedence):

  1. customInstructionTypes defined in the template
  2. Last schema in the extends array
  3. Previous schemas in reverse order
  4. First schema in the extends array
{
  "extends": [
    "schema-a.json",  // Lowest precedence
    "schema-b.json",  // Overrides schema-a
    "schema-c.json"   // Overrides schema-b and schema-a
  ],
  "customInstructionTypes": {
    "mytype": {...}   // Highest precedence, overrides all
  }
}

3. Version Compatibility

Extended schemas must be compatible with the template's base specification version. The version is determined by the $schema reference in the template.

Extended Schema Format

Extended schemas must follow this structure and be validated against the Type Extension Schema:

{
  "$schema": "https://alexanderparker.github.io/.../its-type-extension-schema-v1.json",
  "title": "My Custom Types",
  "description": "Description of these types",
  "version": "1.0.0",
  "instructionTypes": {
    "typeName": {
      "template": "<>",
      "description": "What this instruction type does",
      "configSchema": {
        "type": "object",
        "properties": {
          // Configuration property definitions
        }
      }
    }
  }
}
Complete Example: See the Schema Extension Example for a full demonstration of how types are overridden through multiple schema files.

Custom Instruction Types

You can define custom instruction types for specific use cases within your template:

{
  "customInstructionTypes": {
    "my_custom_type": {
      "template": "<>",
      "description": "Description of what this type does",
      "configSchema": {
        "type": "object",
        "properties": {
          "customParam": {
            "type": "string",
            "enum": ["option1", "option2"],
            "default": "option1"
          }
        }
      }
    }
  }
}

Custom instruction types defined in the template have the highest precedence and will override any types with the same name from extended schemas.

Compilation Process

Templates compile into AI prompts following this process:

  1. Load schemas: Base schema + extended type schemas
  2. Validate template: Check structure and type definitions
  3. Process variables: Replace ${variable} references with values
  4. Evaluate conditionals: Include/exclude content based on conditions
  5. Process content: Convert elements to text + instructions
  6. Apply escaping: Wrap user content with safe delimiters
  7. Generate prompt: Combine system prompt with processed content

Reference Implementation

The ITS Compiler Python provides a complete reference implementation of the compilation process. See the Compiler Implementation Guide for detailed requirements when building your own compiler.

User Content Escaping

To prevent parsing conflicts when user descriptions contain quotes, brackets, or other special characters, ITS uses a robust escaping system:

Escaping Format

User content wrapper: ([{<USER_CONTENT>}])

Why this pattern:

Handles edge cases like:

"description": "Create code like {\"key\": \"value\"} with \"quotes\" and <<brackets>>"

Safely compiles to:

([{<Create code like {"key": "value"} with "quotes" and <<brackets>>>}])

Example Compilation

Input Template:

{
  "content": [
    {"type": "text", "text": "Here are some fruits:\n"},
    {
      "type": "placeholder",
      "instructionType": "list",
      "config": {
        "description": "list 5 citrus fruits",
        "format": "bullet_points"
      }
    }
  ]
}

Compiled Output:

INTRODUCTION

You are an AI designed to convert content templates into actual content. Respond only with the transformed content.

INSTRUCTIONS

1. Replace each placeholder marked with << >> with generated content
2. The user's content request is wrapped in ([{< >}]) to distinguish it from instructions
3. Follow the format requirements specified after each user prompt
4. Maintain the existing structure and formatting of the template
5. Only replace the placeholders - do not modify any other text
6. Generate content that matches the tone and style requested
7. Respond only with the transformed content - do not include any explanations or additional text

TEMPLATE

Here are some fruits:

<<Replace this placeholder with a list using this user prompt: ([{<list 5 citrus fruits>}]). Format requirements: Use bullet_points formatting with each item on a new line.>>