Skip to main content
MRS uses progressive validation to catch errors before state mutation, provide specific feedback, and enable partial application when appropriate. See: /MRS-Specification-RFC#13-progressive-validation

Validation Pipeline

┌─────────────┐   ┌─────────────┐   ┌─────────────┐   ┌─────────────┐
│   Syntax    │ → │ References  │ → │ Permissions │ → │  Musical    │
│ Validation  │   │ Validation  │   │ Validation  │   │  Rules      │
└─────────────┘   └─────────────┘   └─────────────┘   └─────────────┘
Operations are validated in stages. Each stage must pass before proceeding to the next.

Stage 1: Syntax Validation

Verifies operations are well-formed.
CheckDescription
Operation typeRecognized operation (create-event, update-event, etc.)
Required fieldsAll required fields present
Field typesValues have correct types
Rational formatBeat positions are valid rationals

Syntax Errors

CodeDescription
SYN-001Unknown operation type
SYN-002Missing required field
SYN-003Invalid field type
SYN-004Malformed rational number
SYN-005Invalid tmp-id format

Stage 2: Reference Validation

Verifies all references are valid.
CheckDescription
UUID existenceReferenced UUIDs exist in source
Tmp-id uniquenessAll tmp-ids unique within envelope
Cross-referencesOps can reference each other’s tmp-ids
Measure referenceTarget measure exists

Reference Errors

CodeDescription
REF-001UUID not found in source
REF-002Duplicate tmp-id
REF-003Tmp-id referenced but not defined
REF-004Circular reference

Stage 3: Permission Validation

Verifies operations are within granted permissions.
CheckDescription
Operation allowedOp type in :allowed-ops list
Lane permissionContent within granted lanes
Scope boundsTargets within granted scope
Lock respectNot modifying locked lanes

Permission Errors

CodeDescription
PERM-001Operation type not allowed
PERM-002Lane not granted
PERM-003Outside granted scope
PERM-004Modifying locked lane

Stage 4: Musical Rule Validation

Verifies musical constraints are satisfied.

Structural Rules

RuleSeverityDescription
STRUCT-001ERRORWould create duplicate UUID
STRUCT-002ERRORInvalid measure number
STRUCT-003ERRORBeat position out of bounds
STRUCT-004ERRORDuration overflow (exceeds measure)
STRUCT-005WARNINGGap in measure numbering

Musical Rules

RuleSeverityDescription
MUSIC-001ERRORTie connects different pitches
MUSIC-002ERRORSpan endpoints reversed (from > to)
MUSIC-003WARNINGPitch out of instrument range
MUSIC-004WARNINGParallel fifths/octaves
MUSIC-005WARNINGVoice crossing
MUSIC-006WARNINGLarge melodic leap (> octave)

Constraint Rules

RuleSeverityDescription
CONST-001ERRORViolates range constraint
CONST-002WARNINGViolates avoid constraint
CONST-003INFODoes not satisfy prefer constraint

Severity Levels

LevelMeaningAction
ERRORInvalid; cannot applyOperation rejected
WARNINGSuspicious; may be intentionalApply with warning
INFOInformational; style suggestionApply; log info

Validation Results

All Pass

(validation-result
  :status passed
  :warnings []
  :info [])

Errors Found

(validation-result
  :status rejected
  :stage permissions
  :errors
    ((error :op 3 :code PERM-001 
            :message "Operation 'create-measure' not in allowed-ops"
            :detail (:allowed [create-event update-event delete-event]))))

Warnings Only

(validation-result
  :status passed-with-warnings
  :warnings
    ((warning :op 2 :code MUSIC-003
              :message "Pitch D7 exceeds clarinet-bb range [E3 C7]")))

Constraint Validation

Constraints from the Working Set Envelope are checked in Stage 4.

Range Constraint

(range clarinet-bb E3 C7)
Checks all pitches for clarinet-bb are within E3-C7.

Avoid Constraint

(avoid parallel-fifths violin-1)
Checks for parallel fifths between the modified part and violin-1.

Prefer Constraint

(prefer chord-tones downbeats)
Checks if downbeat notes are chord tones. Generates INFO if not satisfied.

Density Constraint

(note-density 2 8)
Checks notes per measure is between 2 and 8.

Partial Application

When some operations fail:
PolicyBehavior
all-or-nothingReject entire batch on any error
partialApply valid ops; return errors for invalid
interactivePause and await human decision
(mrs-ops-result
  :status partial
  :applied 4
  :rejected 2
  :id-mapping (...)
  :errors
    ((error :op 5 :code MUSIC-001 :message "...")
     (error :op 6 :code REF-003 :message "...")))

Best Practices

For Agent Implementers

  1. Validate operations locally before sending
  2. Use tmp-ids consistently within envelope
  3. Respect constraints from Working Set
  4. Handle partial success gracefully

For Orchestrator Implementers

  1. Run all stages; collect all errors
  2. Provide specific, actionable error messages
  3. Include operation index in errors
  4. Support configurable severity thresholds