AI Generation Rules

Rules are constraints that guide StudioBrain’s AI when generating or modifying content for a specific entity type. They ensure generated content stays consistent with the project’s world, tone, and structural requirements.

What Rules Do

When you ask the AI to generate a character backstory, describe a location, or write dialogue, StudioBrain includes the applicable rules for that entity type in the generation prompt. Rules act as guardrails:

  • Enforce naming conventions (e.g. “all elven names must contain an apostrophe”)
  • Maintain world consistency (e.g. “magic does not exist in this setting”)
  • Set structural requirements (e.g. “every location must include a danger level”)
  • Define tone and style (e.g. “descriptions should be concise, no purple prose”)

Rule Formats

StudioBrain supports two rule formats: legacy Markdown and structured YAML. Both can be used side by side.

Legacy Markdown Rules

A Markdown file named {ENTITY_TYPE}_RULES.md (for example CHARACTER_RULES.md). The entity type is taken from the filename. The file content is passed to the AI as context during generation.

# Character Generation Rules
 
## Naming
- Character names must be culturally appropriate for their faction
- No modern Earth names in fantasy settings
 
## Traits
- Maximum 5 personality traits per character
- At least one trait must be a flaw or weakness

Structured YAML Rules

YAML rule files (.yaml / .yml) describe each rule as an item with a category, priority and validation type.

rule_id: character_generation
name: Character generation
entity_type: character
version: "1.0"
priority: high
 
rules:
  - id: char_001
    category: identity
    priority: high
    rule: Character names must fit the cultural context of their faction
    validation_type: error
 
  - id: char_002
    category: narrative
    priority: medium
    rule: Every backstory must include a clear character motivation
    validation_type: warning
 
defaults:
  max_traits: 5

Format Comparison

FeatureMarkdown (*_RULES.md)YAML (*.yaml)
Entity typeFrom the filenameentity_type field (or applies_to), else the filename
StructureFree-form textDiscrete rule items with id, category, priority, rule, validation_type
DefaultsNonedefaults section

YAML Rule Fields

Top-Level Fields

FieldDescription
rule_idIdentifier for the rule set
nameHuman-readable name
entity_typeEntity type the rules apply to (applies_to is also accepted; a list uses its first entry)
versionRule version string
prioritycritical, high, medium (default) or low
rulesList of rule items (below)
defaultsDefault field values passed to the AI as context
validationList of validation entries
system_promptOptional system prompt text for generation
scopeSet to global for a rule set that applies to every entity type

Rule Items

FieldDescription
idRule identifier (auto-numbered if omitted)
categoryGrouping label (default general)
prioritycritical, high, medium (default) or low
ruleThe constraint text
validation_typeerror (violation blocks) or warning (advisory, default)
enabledWhether the rule is active (default true)
applies_toEntity types the rule applies to
forbidden, forbidden_phrasesWords or phrases that content checks reject

Where Rules Live

Rules load from a _Rules/ directory with later layers overriding earlier ones for the same entity type:

_Rules/*_RULES.md   (legacy, root level)
  └── Standard/
        └── Core/
              └── Custom/
                    └── User/   (highest priority)

See Inheritance & Overrides for the general model. In the hosted SaaS, rules are stored per project rather than read from disk: GET /api/rules/:entity_type returns the composed ruleset for a type, and PUT / DELETE on the same path create or remove a tenant override. Installed rulesets from the catalog are bound to the project and applied additively on top.

Creating a Custom Rule

Save a YAML file such as _Rules/Custom/character_generation.yaml (self-hosted), or write the ruleset through PUT /api/rules/:entity_type (cloud). For a custom entity type such as recipe, use entity_type: recipe with your own rule items.

rule_id: recipe_generation
entity_type: recipe
version: "1.0"
 
rules:
  - id: recipe_001
    category: ingredients
    rule: Only use ingredients commonly available in grocery stores
    validation_type: warning
 
  - id: recipe_002
    category: steps
    rule: Each step must be a single clear action
    validation_type: error

How Rules Are Applied

During AI generation:

  1. StudioBrain identifies the entity type being generated.
  2. It resolves the effective ruleset for that type (tenant override, then system or catalog rules, plus any installed rulesets).
  3. The resulting rule text and system prompt are injected into the AI system prompt alongside the template definition and any applicable skills.
  4. The AI generates content within these constraints.

You can check an entity against its rules on demand with POST /api/rules/validate/:entity_type or POST /api/rules/:entity_type/validate-entity.

Next Steps