LLMAssert
Matchers

toBeFormatCompliant

Assert that text conforms to a described structural format

Validates that text conforms to a described structural format. The schema parameter is a natural-language description of the expected format, not a JSON Schema or Zod object.

Usage

await expect(response).toBeFormatCompliant(
  "JSON object with required fields: id (number), name (string), tags (array of strings)",
);

Negation

Verify free-form output:

await expect(response).not.toBeFormatCompliant("numbered list");

Example — structured API response

import { test, expect } from "@llmassert/playwright";

test("AI generates valid product descriptions", async () => {
  const description = await ai.generateProductDescription(product);

  await expect(description).toBeFormatCompliant(
    "Three paragraphs: overview, key features as bullet list, call to action",
  );
});

Effective schema descriptions

The schema parameter is a natural-language description, not a JSON Schema. Be specific about structure, required fields, and data types.

GoodToo vague
"JSON object with fields: id (number), name (string)""JSON"
"Markdown with H2 headers and bullet lists""formatted text"
"Three paragraphs, each 2-4 sentences""a few paragraphs"
"CSV with columns: date, amount, description""tabular data"

Threshold guidance

ThresholdMeaningUse when
0.90Strict — must match all structural elementsAPI response validation, data pipelines
0.75Balanced — key structure present, minor deviations OKContent generation
0.70Default — general format complianceGeneral use

Dashboard type

Appears as assertion type schema in the dashboard.

On this page