Introduction
Introduction to Blocks
Domain-driven validation and orchestration for agentic coding workflows
Blocks is a negotiation layer and semantic compass for human-AI collaboration, detecting drift between code and spec to help you maintain consistency through explicit domain semantics, multi-layer validation, and evolutionary design.
Why Blocks?
Modern AI coding tools (Claude Code, Cursor, GPT engineers) generate code fast — but without a design system, output becomes inconsistent and unmaintainable.
Blocks provides:
- Domain modeling (entities, signals, measures — like Cube.dev/Malloy for code)
- Multi-validator pipelines (schema, shape, lint, domain, chain, shadow, scoring)
- Human-AI collaboration (anyone reads spec, writes code freely, validates, learns from feedback)
- Drift detection (detect when code diverges from spec, decide: fix code or update spec)
The Workflow
Blocks is not a restriction — it's a recovery mechanism for consistency:
- Define domain in
blocks.yml(your source of truth) - Write code freely - humans and AI agents both contribute without restrictions
- Run validation - Blocks detects semantic drift using LLM reasoning
- Review drift report - See new fields, missing outputs, constraint violations, naming inconsistencies
- Decide what to fix - Update code to match spec OR update spec to match code
- Return to consistency - System validates the alignment
Not enforcing rules — helping you reason about drift. Not locking down code — giving you a semantic compass.
Key Features
Domain Modeling
Define your domain semantics in blocks.yml:
- Entities - the "things" in your system
- Signals - domain concepts to extract
- Measures - constraints on outputs
- Philosophy - design principles
Multi-Layer Validation
Blocks is a development-time validator that analyzes source code, not runtime behavior.
Four validator types:
- Schema - Fast, structural validation of I/O signatures
- Shape - Fast, file-based validation of structure
- Domain - AI-powered semantic validation of ALL source files
- Output - User-defined validators that render and check output (future)
Human-AI Collaboration
Works seamlessly with both human developers and AI coding tools (Claude Code, Cursor, etc.):
- Anyone reads
blocks.ymlto understand the domain - Anyone writes code (humans or AI agents)
- Run
blocks run <name>for validation - Review drift report with specific, actionable feedback
- Decide: fix code to match spec OR update spec to match code
- Re-run validation until consistent
CRITICAL: No restrictions on who can edit code. Both humans and AI can freely write and modify any block. Blocks detects drift regardless of authorship.
Drift Detection & Spec Evolution
Blocks detects when code diverges from spec and helps you decide how to resolve it:
Drift scenarios detected:
- New fields not defined in spec
- Missing outputs that should be there
- Constraint violations
- Inconsistent naming patterns
- Blocks in code but not in spec
- Blocks in spec but not in code
Example validation output:
⚠ [domain] Undocumented output field: alerts_es
→ Suggestion: Add alerts_es to outputs in blocks.yml
⚠ [domain] Block "user_profile_enricher" exists in code but not in spec
→ Suggestion: Add to blocks.yml or remove implementationYou decide: Fix code to match spec OR update spec to match code. Anyone (human or AI) can propose spec updates → Human approves → Spec evolves with code.
Not enforcement — negotiation. Blocks doesn't prevent drift, it helps you reason about it and resolve it intentionally.
Quick Example
Here's a simple block that calculates user engagement scores:
domain:
entities:
user:
fields: [id, name, email]
measures:
score_0_1:
constraints:
- "Value must be between 0 and 1."
blocks:
user_engagement_score:
description: "Calculate user engagement score"
inputs:
- name: user
type: entity.user
outputs:
- name: score
type: measure.score_0_1export async function userEngagementScore(user: any) {
// Calculate engagement based on user activity
const score = calculateEngagement(user);
return { score };
}Run validation:
blocks run user_engagement_scoreOutput:
🧱 Blocks Validator
📦 Validating: user_engagement_score
✓ schema ok
✓ shape ok
✓ domain ok
✅ Block "user_engagement_score" passed all validations