Skip to content

AI app generation: prefab generate #157

@jlowin

Description

@jlowin

Summary

Add a prefab generate CLI command that takes a natural language description and produces a working Prefab app.

Motivation

Prefab's JSON wire format is a structured, constrained grammar — exactly the kind of output LLMs produce reliably. This is a unique architectural advantage: generating a Prefab app from a description is fundamentally more reliable than generating imperative UI code, because the output is a data structure with a known schema rather than arbitrary code with complex runtime semantics.

Proposed UX

prefab generate "dashboard with a date range picker, a bar chart of 
  sales by region, and a data table with the underlying records"

Outputs a working app.py file that:

  • Uses the right Prefab components for the description
  • Wires reactive bindings between filters and displays
  • Includes sample data so it runs immediately
  • Is idiomatic, readable, and customizable

How it works

  1. The CLI sends the description + Prefab's component schema to an LLM
  2. The LLM generates either Python code (using Prefab components) or raw JSON matching the wire format
  3. The CLI validates the output against the schema registry
  4. Writes a runnable file and optionally opens it with prefab serve

Why this is uniquely viable for Prefab

  • The JSON schema provides a formal grammar the LLM can target
  • Component schemas in renderer/src/schemas/ serve as the specification
  • Validation catches malformed output before the developer sees it
  • The constrained output space means high reliability vs. generating arbitrary framework code

Scope

  • CLI command: prefab generate "<description>" [--output app.py] [--serve]
  • LLM provider: configurable (default to Claude API)
  • Schema context: auto-include component schemas as LLM context
  • Validation: run generated JSON through Zod schemas before writing

Open questions

  • Should this also work as a Python API (prefab.generate("..."))?
  • Should it support iterative refinement ("add a filter for region")?
  • How to handle data sources — generate with sample data, or wire to a specified tool/endpoint?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement to existing functionality or new capabilities.pythonRelated to the Python SDK: components, actions, serialization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions