← All examples
03

Canonical Grid model

Text And Quality

Portable model for classification, text cleanup, and defensive parsing.

Scale
Medium
Source
03-text-and-quality.grid
Length
25 lines
Collection
Start here
Level
Beginner
Runtime
Portable
Version
1.0.0

Watch it in Grid

See this model in motion.

Watch the model respond in the product, then inspect the exact source and checkpoints on this page.

Companion film

Bad text stays visible

Change a valid invoice reference to malformed text and watch the raw input stay visible while an anchored parse guard returns unparsed and closes the decision as rejected.

44 secGrid 0.63.2
Open film page

What this model gives you

A defensive invoice classifier with regex extraction, normalization, matching, and explicit fallbacks.

10 min to study · Source reviewed 2026-08-25

Continue with guided practice

What to notice

  • Regex and wildcard checks
  • Capture extraction
  • MATCH classification
  • TRY and DEFAULT recovery

Requirements

  • Portable
  • No connector
  • No network

Expected checkpoint

A known state for this walkthrough.

After loading the canonical invoice and owner text.

Invoice valid
TRUEA4 and A7
Extracted year
2026A5
Normalized text
priority:urgent owner:sharedA6
Classification
:accepted / currentB1 / B2
Division fallback
0B3
01 · Validate

Two independent checks admit the invoice

Regex validates the complete shape while a glob checks the expected suffix.

02 · Normalize

Capture and replacement produce reusable text

The year becomes a stable field and owner data is rewritten without changing the raw source.

03 · Recover

Errors and blanks become explicit policy

TRY and DEFAULT keep downstream classification readable.

03-text-and-quality.grid
Get Grid
MODEL "Text And Quality"
DESCRIPTION "Portable model for classification, text cleanup, and defensive parsing."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "portable", "text", "quality"

# Raw text inputs
A1 = "INV-2026-001"
A2 = "priority:urgent owner:ops"
A3 = raw"^INV-\d+-\d+$"

# Parsing and cleanup
A4 = REGEXMATCH(A1, A3)
A5 = REGEXEXTRACT(A1, /INV-(\d+)/)
A6 = REGEXREPLACE(A2, /owner:\w+/, "owner:shared")
A7 = WILDCARDMATCH(A1, glob"INV-*-001")

# Classifications
B1 = A4 AND A7 THEN :accepted ELSE :rejected
B2 = MATCH(A5, "2025" -> "legacy", "2026" -> "current", _ -> "other")
B3 = TRY 10 / 0 ELSE 0
B4 = BLANK DEFAULT "unassigned"
B5 = `invoice={A1} year={A5} state={B1}`

END MODEL