← All posts

Why code-driven AI illustrations fit technical systems

Code-driven illustrations fit technical teams better than free-form image generation when accuracy, versioning, and repeatability matter. The strongest pattern is to use AI to extract structure, then render and verify the visual with code.

Simon Willison argues that code-driven AI illustrations often beat image-model output for technical communication. The claim matters if you ship developer tools, docs, dashboards, or internal systems. In those settings, you need images you can inspect, diff, regenerate, and adapt to new facts.

This is less about art and more about software. A diagram defined in code fits the same workflow as the rest of your system. You review it in Git. You parameterize it. You regenerate it in CI. When the underlying data changes, your image changes with it.

For teams building AI products, this approach also reduces a common failure mode. Free-form image generation produces assets that look polished but encode errors you do not catch until late. Code-driven illustrations shift the work toward explicit structure. That makes them easier to verify and easier to keep aligned with your product.

Treat illustrations as generated artifacts

If your product already produces structured data, your visuals should start from the same source. Think charts, architecture diagrams, sequence flows, entity graphs, feature maps, and UI mock components.

A code-driven illustration usually has three layers:

  • Source data or structured facts
  • A transformation step
  • A rendering target, such as SVG, Canvas, Mermaid, Graphviz, D2, or custom code

This gives you a repeatable pipeline. It also gives you failure points you can inspect.

What to inspect first:

  • Where the facts come from
  • Whether the transformation is deterministic
  • Whether layout changes hide semantic changes
  • Whether labels come from trusted strings or model output
  • Whether the final format supports text search, accessibility, and diffing

A simple example in Go is enough to show the pattern. You do not need a large framework.

package main

import (
    "fmt"
    "os"
)

type Service struct {
    Name string
    X    int
    Y    int
}

func main() {
    services := []Service{
        {Name: "API", X: 40, Y: 40},
        {Name: "Worker", X: 220, Y: 40},
        {Name: "DB", X: 400, Y: 40},
    }

    fmt.Fprintln(os.Stdout, `<svg xmlns="http://www.w3.org/2000/svg" width="520" height="120">`)
    for _, s := range services {
        fmt.Fprintf(os.Stdout, `<rect x="%d" y="%d" width="120" height="50" fill="#eef" stroke="#335"/>`, s.X, s.Y)
        fmt.Fprintf(os.Stdout, `<text x="%d" y="%d" font-family="sans-serif" font-size="14">%s</text>`, s.X+20, s.Y+30, s.Name)
    }
    fmt.Fprintln(os.Stdout, `<line x1="160" y1="65" x2="220" y2="65" stroke="#333"/>`)
    fmt.Fprintln(os.Stdout, `<line x1="340" y1="65" x2="400" y2="65" stroke="#333"/>`)
    fmt.Fprintln(os.Stdout, `</svg>`)
}

This is plain code. You can unit test the input data. You can snapshot-test the output SVG. You can feed the same input into multiple renderers.

Use AI for structure extraction, not final pixels

The strongest use of AI here is upstream. Ask the model to convert rough text into structured objects, relationships, constraints, or layout hints. Then render with code.

This split gives you better control.

Good AI tasks in this workflow:

  • Extract entities and edges from a design note
  • Normalize labels and group related concepts
  • Suggest diagram types from source material
  • Produce JSON for a renderer
  • Explain why a node belongs in a cluster

Weak AI tasks in this workflow:

  • Inventing topology from incomplete notes
  • Producing the final visual with no intermediate structure
  • Rendering text-heavy diagrams as raster images
  • Mixing decorative detail with factual content

The difference is auditability. If a model outputs JSON, you inspect fields, counts, and references. If it outputs a finished image, you inspect by eye. That breaks down fast in dense technical material.

A practical pattern is to force an intermediate schema. For example:

{
  "nodes": [
    {"id": "frontend", "label": "Frontend", "role": "ui"},
    {"id": "api", "label": "API", "role": "service"},
    {"id": "db", "label": "Postgres", "role": "storage"}
  ],
  "edges": [
    {"from": "frontend", "to": "api", "kind": "https"},
    {"from": "api", "to": "db", "kind": "sql"}
  ]
}

Once you have this, the rest is software engineering. Validate unique IDs. Reject unknown edge types. Enforce naming rules. Render only after validation passes.

Prefer SVG and text-first formats

For technical teams, SVG is often the right output. It is inspectable, scriptable, and compact. It works in docs sites, slides, READMEs, and dashboards. It also supports accessibility hooks and post-processing.

Text-first formats bring other benefits:

  • Git diffs stay meaningful
  • Reviewers comment on facts, not style alone
  • Search works across labels
  • Localization is easier
  • Theme changes are cheap
  • Regeneration is trivial in CI

Where teams go wrong:

  • Converting everything to PNG too early
  • Baking labels into paths
  • Letting layout engines reorder nodes without pinning critical constraints
  • Ignoring font availability across environments
  • Embedding unescaped user strings into SVG

The last point matters more than many teams expect. SVG is markup. If any label or URL comes from untrusted input, treat it like any other output context. Escape text. Restrict attributes. Strip scriptable features if the SVG will render in a browser context.

If you publish generated diagrams on the web, inspect the delivery path too. Check content type, CSP, and sanitization rules. A diagram generator belongs in your application threat model.

Build verification into the pipeline

The main gain from code-driven illustrations is not speed. It is reliability. You get that only if you verify the steps.

Useful checks:

  • Schema validation on intermediate data
  • Golden tests for stable outputs
  • Property tests for node and edge counts
  • Lint rules for forbidden labels or missing annotations
  • Visual regression tests for layout drift
  • Accessibility checks for contrast and titles

A simple review flow looks like this:

  1. Store the source facts in JSON, YAML, or code.
  2. Generate SVG in CI.
  3. Fail the build on schema or snapshot mismatches.
  4. Publish the artifact with the commit hash in metadata.

This pattern fits AI systems well. Suppose your LLM produces a system map, safety flow, or prompt-chain diagram from a config repository. If each stage emits inspectable structure, you trace errors back to the step that introduced them.

For web teams, the same principle applies to marketing and support content. A feature matrix, product map, or benchmark chart driven from source data is easier to maintain than a folder full of exported images.

If your site relies on generated assets, AI vs AI: Website Security Check fits one narrow part of the process. It helps you inspect the web delivery surface, such as HTTPS, headers, and exposed files, after you publish those assets.

Keep humans on semantics and constraints

Code-driven does not mean designer-free. It means the designer and engineer work at a different layer.

Humans should define:

  • Which distinctions matter
  • Which data deserves emphasis
  • Which layouts preserve meaning
  • Which color and shape systems encode categories
  • Which annotations prevent misreading

Machines should handle:

  • Repetition
  • Regeneration
  • Scaling to many variants
  • Constraint satisfaction
  • Output formatting

This becomes more important as AI products grow more dynamic. If your app explains a workflow, trust score, model route, or retrieval path with generated visuals, the image is part of the product logic. Treat it with the same discipline you apply to API responses.

The goal is not prettier diagrams. The goal is a visual layer that stays consistent with your system as the system changes.

What to watch next

Watch for more tools that sit between LLMs and renderers. Structured diagram schemas, layout constraint libraries, and SVG diff tooling are all improving. So are model workflows that emit typed objects instead of prose.

If you build with Go or run AI-heavy docs pipelines, this is a useful direction. Start small. Pick one diagram class, define a schema, render to SVG, and put it under test. You will learn fast where your content is stable, where your models drift, and where visuals need stronger constraints.