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 weaknessStructured 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: 5Format Comparison
| Feature | Markdown (*_RULES.md) | YAML (*.yaml) |
|---|---|---|
| Entity type | From the filename | entity_type field (or applies_to), else the filename |
| Structure | Free-form text | Discrete rule items with id, category, priority, rule, validation_type |
| Defaults | None | defaults section |
YAML Rule Fields
Top-Level Fields
| Field | Description |
|---|---|
rule_id | Identifier for the rule set |
name | Human-readable name |
entity_type | Entity type the rules apply to (applies_to is also accepted; a list uses its first entry) |
version | Rule version string |
priority | critical, high, medium (default) or low |
rules | List of rule items (below) |
defaults | Default field values passed to the AI as context |
validation | List of validation entries |
system_prompt | Optional system prompt text for generation |
scope | Set to global for a rule set that applies to every entity type |
Rule Items
| Field | Description |
|---|---|
id | Rule identifier (auto-numbered if omitted) |
category | Grouping label (default general) |
priority | critical, high, medium (default) or low |
rule | The constraint text |
validation_type | error (violation blocks) or warning (advisory, default) |
enabled | Whether the rule is active (default true) |
applies_to | Entity types the rule applies to |
forbidden, forbidden_phrases | Words 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: errorHow Rules Are Applied
During AI generation:
- StudioBrain identifies the entity type being generated.
- It resolves the effective ruleset for that type (tenant override, then system or catalog rules, plus any installed rulesets).
- The resulting rule text and system prompt are injected into the AI system prompt alongside the template definition and any applicable skills.
- 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
- Template System Overview — What templates are and how they work
- Inheritance & Overrides — How resolution layers work
- Agent Skills — AI capabilities that complement rules