Prompting Guide
How to make any LLM write KERN. You don't need to learn KERN — you need to learn how to ask.
Why have LLMs write KERN?
70% fewer tokens
LLMs generate KERN faster and cheaper. Less output = less cost, less latency, fewer errors.
Semantic clarity
KERN nodes map to UI concepts. The LLM thinks in components, not syntax. Less hallucination.
Target flexibility
Generate once, compile to any target. The LLM doesn't need to know React vs Vue vs Native.
The system prompt
Add this to your LLM's system prompt. That's all it needs:
You can generate UI and backend code in KERN format.
KERN is an indent-based language that compiles to
Next.js, React, Express, and 8 other targets.
Syntax: indent-based, 2 spaces per level.
node type prop=value {style:shorthand}
Quick reference:
- page name=X route=/path
- text value=X tag=h1|h2|p|span {fs:N,fw:N,c:COLOR}
- button text=X to=path|onClick=handler
- row/col/grid for layout
- card {bg:COLOR,br:N,p:N,border:COLOR}
- server, route, middleware for backends
- machine, transition for state machines
Style shorthands: p=padding m=margin w=width h=height
bg=backgroundColor c=color fs=fontSize fw=fontWeight
br=borderRadius jc=justifyContent ai=alignItems
Full spec: https://kernlang.dev/llm/spec.kern~20 lines. The LLM now generates KERN instead of verbose JSX/TSX. For deeper knowledge, point it to the spec URL — one fetch, complete understanding.
Prompt patterns
Pattern 1: Page from description
Prompt:
Create a dark-themed landing page for a SaaS product called CloudDash with a hero, 3 feature cards, and a CTA. Output as .kernThe LLM generates ~15 lines of KERN instead of ~80 lines of JSX.
Pattern 2: API from spec
Prompt:
Generate an Express API in KERN with CRUD routes for a 'projects' resource. Include auth middleware and schema validation.The LLM generates a server node with routes — compiles to a full Express app with error handling.
Pattern 3: State machine from flow
Prompt:
Model a payment flow as a KERN state machine: pending -> processing -> succeeded/failed, with retry from failed.The LLM generates a machine node — compiles to enum, type guards, and transition function.
Pattern 4: Point to the spec
Prompt:
Read the KERN spec at https://kernlang.dev/llm/spec.kern and then generate a docs page for our API reference.The LLM fetches the spec, learns the full language in one request, and generates correctly.
Tips
Always specify 'Output as .kern' or 'Write in KERN format' in your prompt.
Include the target: 'for Next.js' or 'for Express'. The LLM can use target-specific nodes.
For complex pages, describe the layout: 'hero section, then 3-column feature grid, then CTA'.
Point the LLM to kernlang.dev/llm/spec.kern for the full reference. One fetch, complete knowledge.
KERN is 70% cheaper than having the LLM generate TypeScript directly. Use it for batch generation.