Skip to content

graflo.architecture.schema.context.type_sheet

Type sheet: a schema as a compact, closed-world vocabulary for a language model.

One line per vertex type and per edge, each followed by its typed properties. The output is byte-deterministic — the same schema always renders the same bytes, whatever order its elements were declared in — so a prompt built around it keeps hitting response and prefix caches.

Classes

Functions:

render_type_sheet(schema)

Render schema as a type sheet.

The notation legend comes first, then vertices sorted by name, then edges sorted by (source, target, relation). Properties keep their declared order; minted key properties are left out, since no text supplies them. The sheet ends with the closed-world sentence: a type, relation or property absent from it does not exist.

Source code in graflo/architecture/schema/context/type_sheet.py
def render_type_sheet(schema: Schema) -> str:
    """Render *schema* as a type sheet.

    The notation legend comes first, then vertices sorted by name, then edges
    sorted by ``(source, target, relation)``. Properties keep their declared
    order; minted key properties are left out, since no text supplies them.
    The sheet ends with the closed-world sentence: a type, relation or
    property absent from it does not exist.
    """
    core = schema.core_schema
    lines = [_HEADER, "", "## Vertices"]
    for vertex in sorted(core.vertex_config.vertices, key=lambda v: v.name):
        lines.extend(_vertex_lines(vertex))
    edges = sorted(core.edge_config.values(), key=lambda e: edge_sort_key(e.edge_id))
    if edges:
        lines.extend(["", "## Edges"])
        for edge in edges:
            lines.extend(_edge_lines(edge))
    lines.extend(["", _FOOTER])
    return "\n".join(lines) + "\n"