Skip to content
VerificationWould you notice if your agent drifted in production?Explore the 5-stage harness›
Specification Language

Field Validation & Invariants

Aegil implements dual-sided validation by compiling declarative field constraints into both client-side UI guards and server-side transaction boundaries. This ensures instant UI feedback on mobile and web while maintaining uncompromised database integrity against out-of-bounds inputs.

namespace Store;
@entity({ table: "products" })
model Product {
@pk
id: uuid;
@validate({ minLength: 3, maxLength: 80 })
name: string;
@validate({ minLength: 10, maxLength: 1000 })
description: string;
@validate({ min: 1, max: 100000 })
priceInCents: int;
@validate({ min: 0, max: 999 })
stockQuantity: int = 0;
@validate({ pattern: "^[A-Z]{3}-[0-9]{4}$" })
sku: string;
createdAt: utcDateTime;
}

Parameter Applies to Meaning Example
minLength string Minimum number of characters (inclusive). @validate({ minLength: 3 })
maxLength string Maximum number of characters (inclusive). @validate({ maxLength: 100 })
min int, float Minimum numeric value (inclusive). @validate({ min: 1 })
max int, float Maximum numeric value (inclusive). @validate({ max: 500 })
pattern string Regular expression the string must match. @validate({ pattern: "^[a-z0-9_-]+$" })

Aegil enforces validation at two independent layers:

  1. Client-side guard: The generated Flutter BLoC validates arguments before dispatching network requests. If validation fails, an error is surfaced immediately in the UI without a network round-trip.
  2. Server-side guard: The Serverpod endpoint validates inputs in the transaction pipeline. Even if a caller bypasses the client app and calls the API directly, invalid data is rejected before touching the database.

Automatic boundary testing in aegil verify

Section titled “Automatic boundary testing in aegil verify”

When you run aegil verify, the dynamic invariant harness automatically generates and executes test cases for every boundary:

  • Lower boundary: Tests min (must succeed) and min - 1 (must fail).
  • Upper boundary: Tests max (must succeed) and max + 1 (must fail).
  • String length: Tests strings of exact lengths minLength, maxLength, minLength - 1, and maxLength + 1.

You never have to write repetitive boundary unit tests by hand; Aegil generates and verifies them deterministically.


What you see Why What to do
ERR_VALIDATION_SYNTAX A @validate decorator has invalid bounds (e.g. min > max or minLength < 0). Fix the bounds in the @validate decorator.
Invariant test failure A hook or custom logic produced a value outside the declared @validate bounds. Update the hook logic to respect the bounds, or adjust the spec if requirements changed.