Reading OpenUI Lang

OpenUI Lang is a list of one-line assignments. Each line names a piece of the interface, and the names wire the pieces into a tree. Once you can read one line, you can read any program a model writes.

By the end of this lesson you can

  • name every part of a program: statement, identifier, root, reference, component call, arguments and values;
  • map a call such as TextContent("Revenue", "large-heavy") onto its signature, argument by argument;
  • draw the element tree a program describes by following its references from root;
  • state the three rules models most often break: every statement must be reachable, arguments are positional, and optional arguments can only be dropped from the end.

One program, labelled

Here is a complete program: a heading and a bar chart. It is four statements, one per line, and every statement has the same shape, identifier = Expression. Step through the figure to see what each part is called and what it does.

Anatomy of a program

root = Stack([title, chart]) title = TextContent("Revenue", "large-heavy") chart = BarChart(["NA", "EU", "APAC"], [rev], "grouped") rev = Series("Revenue ($k)", [820, 560, 390]) StatementOne line, one assignment: identifier = Expression. A newline inside brackets does not end it. IdentifierThe name on the left. It is how other statements refer to this one. If a name repeats, the later line wins. root, the entry pointRendering starts here. Its value must be a component, here the library's root component, Stack. ReferencesA bare name inside an expression points at the statement with that name, even one defined further down. Component callsA capitalised name from the component library, with arguments in parentheses. Each one becomes an element. Positional argumentsNo names, only order: the first value is TextContent's text, the second its size. The signature says which is which. ValuesStrings, numbers, arrays (here), and also true / false, null and {key: value} objects. Values can nest.
  1. A statement is one line: identifier = Expression. This program has four. Statements are separated by newlines outside brackets, so a long array may wrap over several lines and still be one statement.
  2. The identifier on the left names the statement. Names are how the pieces connect. If two statements share a name, the later one wins, and a line with no = is silently skipped.
  3. root is the entry point. The renderer starts here and draws only what it can reach from here. Its value must be a component, and for the stock library that is Stack.
  4. A bare name inside an expression, such as title or rev, is a reference. It stands for the value of the statement with that name. The arrows show each reference landing on its definition, all of them further down the text. Forward references are allowed.
  5. A capitalised name followed by parentheses is a component call: Stack, TextContent, BarChart, Series. The name must exist in the component library the app gave the renderer.
  6. Arguments are positional. "Revenue" is the text because it comes first; "large-heavy" is the size because it comes second. There are no argument names in the language.
  7. Everything else is a value: strings in double quotes, numbers, arrays in square brackets, and also true, false, null and {key: value} objects. A value can contain component calls and references, as [rev] does.

The table below lists every value form you will meet in this course. The ones in the last rows ($variables, @ calls, operators) only appear when the app turns on state or tools, and they get lessons of their own.

FormExampleNotes
Component callTag("Q3", null, "sm")Becomes an element in the tree.
String"Revenue ($k)"Double quotes, backslash escapes.
Number820, 12.5, -1
Boolean, nulltrue, false, nullnull also skips an optional argument.
Array[title, chart]Children lists are arrays.
Object{required: true}Keys are bare names, so here a colon is correct.
ReferencetitleThe value of the statement named title.
State, built-ins, operators$city, @Count(rows), a + bSee Reactive state and Query and Mutation.

From signature to call

How does the model know that the first argument of TextContent is the text? The app told it. Each component in the library is defined with a Zod schema, and the order of the keys in that schema becomes the order of the arguments. The generated system prompt prints that order as a signature line, and the parser uses the same order to turn the model's values back into named props.

One schema, one signature, one call

Zod schema in the app's library (key order matters) z.object({ text: z.string(), size: z.enum(["small", …, "large-heavy"]).optional() }) Signature line in the system prompt TextContent( text: string size?: "small" | … | "large-heavy" position 1, required position 2, optional (the ?) The call the model writes TextContent( "Revenue", "large-heavy") "large-heavy", "Revenue") not a size Element node { typeName: "TextContent", props: { text: "Revenue", size: "large-heavy" } } type-mismatch: field "/size" expects one of ["small", …, "large-heavy"] optional prop dropped → { text: "large-heavy" } renders the word "large-heavy"
  1. The app defines TextContent with a Zod object whose keys are text, then size. That order is the whole contract.
  2. The library turns the schema into a signature line for the system prompt: TextContent(text: string, size?: "small" | "default" | "large" | "small-heavy" | "large-heavy"). A ? marks an optional argument. Required keys come first in the schema so that optional ones can be left off the end.
  3. The model writes only values, in signature order: TextContent("Revenue", "large-heavy").
  4. The parser maps position 1 to the first key, text, and checks it is a string.
  5. Position 2 maps to size. "large-heavy" is one of the allowed values, so it passes.
  6. The result is an element node with named props, exactly what a React component receives: { text: "Revenue", size: "large-heavy" }.
  7. Swap the two values and the meaning changes. text becomes "large-heavy", which is a valid string. size gets "Revenue", which is not an allowed size, so the parser reports type-mismatch and drops that optional prop. The page shows the words "large-heavy" in the default size. Nothing crashes, and the screen is wrong.

The signature is the only description of a component the model ever sees, so it is worth reading the real ones. These are four of the stock library's lines, exactly as openuiLibrary prints them (descriptions trimmed):

Stack(children: any[], direction?: "row" | "column", gap?: "none" | "xs" | "s" | "m" | "l" | "xl" | "2xl", align?: …, justify?: …, wrap?: boolean)
TextContent(text: string, size?: "small" | "default" | "large" | "small-heavy" | "large-heavy")
Tag(text: string, icon?: Icon, size?: "sm" | "md" | "lg", variant?: "neutral" | "info" | "success" | "warning" | "danger")
BarChart(labels: string[], series: Series[], variant?: "grouped" | "stacked", xLabel?: string, yLabel?: string, height?: number)

Series[] in BarChart means the slot only accepts Series elements. That comes from z.array(Series.ref) in the schema, covered in Defining components.

References build the tree

The text is a flat list of lines, but the interface is a tree. The tree comes from the references: start at root, replace every name with the statement it points to, and repeat. The order of lines in the text does not matter for the finished tree. It matters a great deal while the text is still streaming, which is the next lesson.

From lines to a tree

root = Stack([title, chart]) title = TextContent("Revenue", "large-heavy") chart = BarChart(["NA", "EU", "APAC"], [rev], "grouped") rev = Series("Revenue ($k)", [820, 560, 390]) note = TextContent("never shown") Stack title ? chart ? TextContent BarChart rev ? Series noteorphaned: no path from root unresolved names are dashed meta.orphaned: ["note"], meta.errors: []
  1. root = Stack([title, chart]) creates a Stack with two children. Their names are known, their statements are not yet: both are unresolved.
  2. title arrives and its slot becomes a TextContent element.
  3. chart arrives as a BarChart. Its series list holds one more name, rev, which is now the only unresolved one.
  4. rev arrives as a Series. Every name resolves, so the tree is complete.
  5. note is a valid statement, but nothing refers to it. There is no path from root, so it never renders. The parser raises no error; it lists the name in meta.orphaned. This is the most common silent failure in model output: the model writes a piece and forgets to put it in a parent's children.
  6. The finished tree is the same whatever order the lines came in. Write rev first and root last and you get the same four elements once the text is complete.

Try it: edit a program

The editor re-renders 150 ms after you stop typing. Below it, a status line shows what the parser found: statements, unresolved names and orphaned statements. Errors appear in the list the real Renderer passes to onError. Work through the exercises in order. For each one, predict first, then make the change (type it, or press the button), then open "What should happen".

  1. 1. Add a Tag. Add this line, then add badge to the root array between title and chart. The null skips the optional icon argument so that "sm" lands in size.

    badge = Tag("Q3", null, "sm", "success")

    Predict: where does the tag appear, and what happens if you add the line but forget to edit root?

    What should happen

    A green "Q3" pill appears between the heading and the chart, because children render in array order. Before you add badge to the array, nothing appears and the status line shows orphaned: badge: a valid statement that nothing reaches.

  2. 2. Break it: reorder the arguments. Change the heading to TextContent("large-heavy", "Revenue").

    Predict: does the heading disappear, show "Revenue", or something else? How many errors?

    What should happen

    The heading reads "large-heavy" in normal-sized text. The first value is always the text, so the text is now the size name. "Revenue" lands in size, fails the enum check, and that optional prop is dropped with one type-mismatch error. Order is meaning: there is no way to say "this one is the size" except by putting it second.

  3. 3. Reference a new statement. Add a note below everything else, then make it render.

    note = Callout("info", "Source", "Q3 board pack, unaudited")

    Predict: what renders after you add only the line? Is there an error?

    What should happen

    With only the line, the page does not change and the error list stays empty. The status line shows orphaned: note. Add note to the root array and the callout appears where you put it in the list. A statement that is defined but never referenced is dropped without an error.

  4. 4. Skip an argument in the middle. Change the tag from exercise 1 to Tag("Q3", "sm"), leaving out the null.

    Predict: is the tag small?

    What should happen

    The tag renders at its default size with a type-mismatch error: field "/icon" expects Icon but got string. "sm" is the second value, so it goes to the second parameter, icon, not to size. Optional arguments can be left off only at the end; to skip one in the middle, write null in its place.

The editor runs the course's teaching simulator, a subset of @openuidev/react-lang that draws about 20 of the 95 stock components as plain HTML. The signatures, parse results and error messages above match the real parser; the visual styling does not.

Rules worth memorising

The generated system prompt lists these rules for the model. Models still break them, and when they do, the parser usually renders what it can without complaint. Knowing them lets you read a broken screen and see the cause.

OpenUI rule

Arguments are positional. They map to props by Zod key order. There is no name: value syntax for arguments: TextContent(text: "Revenue") is not a named argument, and the statement is dropped. When the model gets it wrong shows exactly what the parser makes of it.

OpenUI rule

Optional arguments can be omitted only from the end. To skip one in the middle, pass null: Tag("Q3", null, "sm", "success"). This is why schemas put required keys first.

OpenUI rule

Every statement except root must be referenced. The prompt tells the model "Unreferenced variables are silently dropped and will NOT render." The parser lists them in meta.orphaned and reports no error.

Myth

"The renderer draws statements in the order they appear." It draws the tree reachable from root, in the order of each children array. Line order only decides when each piece can appear during streaming.

Quick check

The signature is Callout(variant: "info" | "warning" | "error" | "success" | "neutral", title: string, description: string, visible?: boolean). Which call is correct?

  • Callout(title: "Q3", variant: "info", description: "Up 12%")
  • Callout("info", "Q3", "Up 12%")
  • Callout("Q3", "Up 12%", "info")
Values only, in signature order: variant, title, description. The optional visible is left off the end. Named arguments are not part of the language, and Callout("Q3", "Up 12%", "info") puts every value in the wrong slot.

A program defines footer = TextContent("Updated today"), but the footer never shows and the error list is empty. What is the most likely cause?

  • TextContent needs a size argument to display anything
  • The line must come before the root line to be seen
  • No statement reachable from root refers to footer
An unreferenced statement is orphaned: it is dropped with no error and listed in meta.orphaned. Size is optional, and forward references mean line order does not matter for the final tree.

Why do component schemas put required keys before optional ones?

  • Zod rejects a schema that lists optional keys before required ones
  • Arguments are positional, so only trailing ones can be skipped; optional keys go last
  • The prompt generator sorts them anyway, so the order is only cosmetic
Key order is argument order. If an optional key sat in the middle, every call that skipped it would need a null placeholder, and every call that forgot the placeholder would shift its later values into the wrong props.

Recap