Skip to main content

Validation Rules

The IR validator enforces structural correctness before any writer runs.

Every error carries a rule id, a location (section, row group, row, column), and a message. Rule ids are the strings below, both in Display output ([COL_COUNT] …) and when errors are serialized.

Version

Rule Description
IR_VERSION ir_version isn’t MAJOR.MINOR (ASCII digits, as in "1.0"), or its major version isn’t 1, the one this gridwell reads. Checked first. A newer minor version ("1.3") is valid, with a warning; see Versions

Limits

Rule Description
LIMIT_EXCEEDED config.table_cols > 16,384, a section has more than 1,048,576 rows, or the table has more than 50 million cells. Checked after the version; the other checks are skipped when a limit is exceeded. Limits are configurable from Rust (validate_with_limits).

Structural Rules

Rule Description
COL_COUNT Every row (header, data and summary) has exactly config.table_cols cell objects; spanned positions hold placeholders
ROW_COUNT thead has config.header_rows rows, and data rows (not summary rows) total config.body_rows: each checked when it is given
COLSPEC_LENGTH column_spec has config.table_cols entries
STUB_CONTIGUOUS The stub is a block at the left: config.stub_cols is at most config.table_cols, and no cell flagged is_stub starts to the right of the stub columns
STYLE_REFS_VALID Every style_id refers to a style definition or composition, wherever it appears: header lines, columns, rows, cells, group labels, notes and styled_text nodes. A composition’s extends refers to a definition (not a composition)
FOOTNOTE_REFS_VALID Every footnote_mark refers to a defined footnote, wherever it appears: cells (including summary rows), header lines, group labels, and the notes themselves
SUMMARY_REQUIRES_STUB A group with summary rows requires config.stub_cols >= 1
UNKNOWN_VALUE A keyword field holds a value outside its allowed set (see Keyword values)
INVALID_COLOR A color field is not a CSS color (see Colors)
INVALID_LENGTH A length field does not parse, or uses a form its field does not allow (see Lengths)
INVALID_STYLE_ID A style id (a key of styles.defs or styles.compositions) is empty or uses a character other than ASCII letters, digits, _ and -
DUPLICATE_ID Two footnotes have the same id, or a style id is a key of both styles.defs and styles.compositions: a reference to it would be ambiguous
INVALID_LANG config.lang is not a well-formed BCP 47 language tag: subtags of ASCII letters and digits separated by - (fr-CA, not fr_CA), as in ar, zh-Hant-TW, es-419 or a private-use x-… tag
INVALID_HREF A text run’s href is not a link gridwell writes: an absolute http or https URL with a host, or a mailto URL with an address, without whitespace or control characters (the scheme matched ignoring case). Other schemes, such as javascript:, data: and file:, could run code or open a local file when the link is followed
INVALID_TABLE_ID config.id is not an HTML id: it is empty or has whitespace
INVALID_TYPED_VALUE A cell’s typed_value isn’t in its type’s form: a string value that isn’t a JSON string, or a duration value that isn’t an ISO 8601 duration string ("PT1H30M")

Span Rules

Spans are checked per section: the header, each group’s data rows, and each group’s summary rows. A span never crosses a section.

Rule Description
SPAN_ZERO_VALUE colspan or rowspan is 0
SPAN_OVERFLOW_RIGHT col + colspan > table_cols: span exceeds the right edge
SPAN_OVERFLOW_BOTTOM row + rowspan > section rows: span exceeds the section
SPAN_OVERLAP Two spans claim the same (row, col) position
SPAN_PLACEHOLDER_MISMATCH A placeholder that no cell’s colspan or rowspan covers
SPAN_GAP A grid position with no cell object at all. A row with too few cells is already reported as COL_COUNT (and its section’s spans are then not checked), so validate() reports this only through OccupancyGrid::materialize used directly
SPAN_PLACEHOLDER_HAS_CONTENT A placeholder cell has non-empty content

Keyword values

Keyword fields are matched ignoring case and surrounding whitespace, and the aliases below are accepted. An unrecognized value still parses: it is kept verbatim (and round-trips unchanged) and reported as UNKNOWN_VALUE, so every bad value is listed at once. Known values are written back in their canonical spelling. In a table of a newer minor version, a value this gridwell doesn’t know isn’t an error: it may be one that version added.

Field Allowed values (aliases)
column_spec[].align, text_align left, center (centre), right, justify, char
vertical_align top, middle, bottom, baseline, super, sub
row.role column_label, spanner_label, summary_row (summary), grand_summary_row (grand_summary)
cell.scope col, colgroup, row, rowgroup
table.tbody[].summary_placement bottom, top
config.page_break_mode avoid, allow, force-between-groups (force_between_groups)
config.dir ltr, rtl, auto
border.*.style none, hidden, solid, dashed, dotted, double
font_weight normal, bold, bolder, lighter, or a number 1–1000 (JSON string or number)
font_style normal, italic, oblique
text_transform none, uppercase, lowercase, capitalize
text_decoration none, underline, overline, line-through (line_through)
white_space normal, nowrap, pre, pre-wrap, pre-line, break-spaces
word_break normal, break-all, keep-all, break-word
overflow, config.container_overflow visible, hidden, clip, scroll, auto
text_overflow clip, ellipsis
conditional selector.row_parity even, odd
conditional selector.scope tbody (body), thead (head), table (all)
typed_value.type string (str, text, character), number (float, double, numeric), integer (int), boolean (bool, logical), date, datetime (timestamp), time, duration

Colors

color, background_color and border.*.color (in style definitions, composition overrides and conditional styles), and config.rules.*.color, accept, ignoring case and surrounding whitespace:

Form Examples
CSS named color (all 148) red, steelblue, RebeccaPurple, grey
transparent paints nothing
Hex #abc, #abcd, #aabbcc, #aabbccdd
rgb() / rgba(), comma syntax rgb(255, 0, 0), rgba(255, 0, 0, 0.5), rgb(100%, 50%, 0%)
rgb() / rgba(), space syntax rgb(255 0 0), rgb(255 0 0 / 50%)
hsl() / hsla() hsl(120, 100%, 25%), hsl(120deg 100% 25% / 0.5); hue units deg, grad, rad, turn

Out-of-range channels clamp, as in CSS. Writers receive the parsed color, never the source text: HTML and SVG emit #RRGGBB (or rgba() when translucent), Typst keeps alpha as #RRGGBBAA, and formats without alpha (LaTeX, RTF, DOCX, PPTX, ANSI) drop it. A fully transparent color paints nothing in every format.

Lengths

A length is a finite number followed by a unit, px, pt, em, rem, in, cm, mm, % or fr (case-insensitive, no space before the unit), or auto. A bare 0 is allowed; any other number needs a unit. Each field accepts only the forms that make sense for it:

Field Units % fr auto Negative
column_spec[].width ✓ ✓ ✓ ✓
column_spec[].min_width, max_width ✓ ✓
config.table_width, container_width, container_height ✓ ✓ ✓
image.width, image.height (image nodes, in any content) ✓ ✓ ✓
style min_width, max_width, padding.* (definitions, composition overrides, conditional styles) ✓ ✓
style indent ✓ ✓ ✓
style border.*.width, config.rules.*.width ✓
style font_size ✓ ✓

font_size also accepts the CSS size keywords xx-small, x-small, small, medium, large, x-large, xx-large, xxx-large, smaller and larger.

How Validation Works

The validator materializes a 2D occupancy grid for each section:

  1. Allocate a rows × cols grid
  2. Walk every cell in document order
  3. For each cell with rowspan=R, colspan=C at position (r, c):
    • Claim all positions (r..r+R, c..c+C)
    • If already occupied → SPAN_OVERLAP error
    • If out of bounds → SPAN_OVERFLOW_RIGHT / SPAN_OVERFLOW_BOTTOM error
  4. Report any position no cell covers as SPAN_GAP

Error Output

Each error includes the rule name, location, and a human-readable message. A message says where the problem is as the IR does, counting from 0: thead row 0, tbody group 1 row 2 (a group’s data rows), tbody group 1 summary row 0 (its summary rows), the cell at tbody group 0 (row=1, col=2), the label of tbody group 1, or a field’s path, such as column_spec[1].width or footer.footnotes[0].

[COL_COUNT] tbody group 0 row 0 has 4 cells but config.table_cols is 3
[SPAN_OVERFLOW_RIGHT] Cell at tbody group 0 (row=1, col=2) has colspan=2 but table only has 3 columns (would need col index up to 3)
[SPAN_PLACEHOLDER_HAS_CONTENT] Placeholder cell at tbody group 0 (row=0, col=2) has non-empty content
[STYLE_REFS_VALID] style_id "bold" of the cell at tbody group 0 (row=1, col=0) is not defined in styles.defs or styles.compositions
[DUPLICATE_ID] footer.footnotes[1] has the id "n" of footer.footnotes[0]: footnote ids must be unique
[INVALID_LENGTH] column_spec[1].width is "-5px", which is not valid here: it is negative (expected a non-negative length (px, pt, em, rem, in, cm, mm), or a percentage, or a fraction (fr), or auto)
[INVALID_LANG] config.lang is "fr_CA", which is not a language tag: subtags are separated by `-`, not `_` (fr-CA, not fr_CA)
[IR_VERSION] ir_version is "2.0", IR 2, and this gridwell reads only IR 1.x (a newer gridwell may read it)

When the table is of a newer minor version, the errors end with a note. What that version may have added (a keyword value, a length unit, a color form or a link scheme) isn’t an error there, so the errors listed are errors to a gridwell that reads it too.

(the table is IR 1.3, newer than the IR 1.0 this gridwell reads; what a newer IR version added isn't an error, and is left out)

Warnings

A valid table can still use a feature an output format can’t express: LaTeX can’t align one cell to the bottom of its row, and Typst has no double borders. The writer then draws something close, and you can ask for a warning first. A warning doesn’t fail validation or stop rendering.

Each warning for a feature has the rule id UNSUPPORTED_FEATURE, the format, the feature (named as in the feature matrix, or for a format’s own limits, as below), where the table uses it (the first place, and how many others), and what the writer draws instead:

[UNSUPPORTED_FEATURE] typst can't express border-double (head row 1, column 1 and 2 other places): Typst strokes have no double line; a double border is drawn solid
Format Feature Warned for
latex font-family A font family, anywhere. A cell or group label in a monospace family is \texttt, and system-ui and the like are drawn in no format: neither is warned
latex vertical-align A middle or bottom cell beside one that may be taller: it breaks lines, has raw LaTeX, sits in a column with a width, or is in a larger font size. A cell spanning rows is centered on them, so only bottom is warned there
latex border-styles A dashed or dotted left or right border on a cell or group label
latex lang A config.lang: the language is the document’s, set up by babel or polyglossia
latex rtl A right-to-left table (dir: rtl, or auto with right-to-left text): it is written left to right
typst border-double A double border on a cell or group label
typst, svg image An image that isn’t a PNG, JPEG, GIF or SVG data: URI (one linked by URL or path)
rtf image An image that isn’t a PNG or JPEG data: URI
docx image An image that isn’t a PNG, JPEG or GIF data: URI
xlsx image An image that isn’t a PNG, JPEG or GIF data: URI alone in its cell or line, or one in a footnote
latex, pptx, ansi image Any image
rtf lang A config.lang: RTF’s \lang takes a Windows language id, which the writer doesn’t map tags to yet
ansi rtl A right-to-left table: a terminal shows the columns left to right
xlsx lang A config.lang: a spreadsheet’s cells have no language
xlsx text-length Text over a cell’s 32,767 characters (a footnote’s counting its mark and the space after it): the rest is cut
xlsx rich-text-length Rich text within 32,767 characters that its formatting markup takes over them: it is written without its formatting

A language or a direction is the table’s as a whole, warned for at the table. Places count from 1: the title, the subtitle, header line 1, head row 1, column 2, group 1 row 3, column 2, group 1 summary row 1, column 1, the label of group 2, footnote 1, source note 1. A row counts within its part of the IR (the head, or a group’s rows or summary rows), and a column within column_spec, hidden columns included. A cell in a hidden column isn’t drawn, so it isn’t warned for.

A newer minor version

A table of a newer minor IR version than this gridwell reads renders, leaving out what that version added. It is warned for first, for any format, with the rule id NEWER_IR_VERSION:

[NEWER_IR_VERSION] the table is IR 1.3, newer than the IR 1.0 this gridwell reads: anything a newer IR version added is left out (a newer gridwell may render it)

A newer version may add keyword values, length units, color forms and link schemes, so in its tables a value this gridwell doesn’t know isn’t an error. It is read as unset: an optional field is left out, one with a default takes it, a link’s text is drawn without the link, and a typed value of an unknown type is left out. A conditional style whose selector has an unknown value applies to no row. Each is warned for, after the version, with the rule id IGNORED_VALUE and the error it would be in a table of this version:

[IGNORED_VALUE] column_spec[0].align is "diagonal", which is not one of: left, center, right, justify, char; the default, left, is used

In a table of IR 1.0 or an older minor, the same value is an error. Some things are read the same way in a table of any version, since a newer one may add them:

  • A field this gridwell doesn’t know is ignored, without a warning.
  • A content node of a type this gridwell doesn’t know is drawn as its fallback (content nodes), or as nothing, without a warning.
  • A conditional style’s selector with a field this gridwell doesn’t know would narrow the rows it matches in a way this gridwell can’t, so the style applies to no row. It is warned for with the rule id IGNORED_SELECTOR:
[IGNORED_SELECTOR] styles.conditionals[0].selector has a field this gridwell doesn't read ("col_parity"); the conditional style applies to no row

Python and R also warn when they parse such a table (a UserWarning, an R warning()).

Warnings are for a valid table: asking for them for an invalid one is the same error rendering it would be.

Usage

gridwell validate table.json
# Exit code 0 = valid, 1 = errors found
# Warnings for every format, or one (they don't change the exit code)
gridwell validate --to latex table.json
# convert prints its format's warnings to stderr
let errors = table.validate();
// errors: Vec<ValidationError>
let warnings = gridwell_render::warnings(&table, Some("latex"))?;
// warnings: Vec<Warning>; None for every format
errors = table.validate()
# errors: list[str]
warnings = table.warnings("latex")
# warnings: list[str]; table.warnings() for every format
errors <- gw_validate(tbl)
# errors: character vector
warnings <- gw_warnings(tbl, "latex")
# warnings: character vector; gw_warnings(tbl) for every format
GridwellError *invalid = gridwell_validate(table);
// null if valid, else an error listing every problem
GridwellError *err = NULL;
GridwellTextResult w = gridwell_warnings(table, "latex", &err);
// one warning per line ("" if none); NULL for every format
gridwell_free_text_result(w);