Rho AI / LLM Guide

For AI app developers: make LLMs reliably generate Rho format .md. Rho is AI-friendly by design — but the right prompt / schema / repair patterns can lift accuracy from 80% to 99%+.


Who this guide is for

  • ✅ AI application developers: have ChatGPT / Claude / Gemini / your self-hosted LLM produce Rho format content
  • ✅ Prompt engineers: tune prompts so LLMs get it right on first try
  • ✅ Education AI / learning platforms: have AI directly generate interactive explanations
  • ✅ Data science / analytics assistants: have AI directly produce chart + slider exploration docs
  • ✅ Automated documentation systems: structured data → AI → Rho doc

Why Rho is AI-generation-friendly

1. Compact + unambiguous syntax

\```interact
slider weight 40 120 70 1
template stl: [BMI] -> [{weight / (height * height):.1f}]
\```

Compared to "write a React component with useState, useEffect, Chart.js," Rho uses 10-20× fewer tokens — LLM error rate drops 10-20×.

2. Structure inside markdown

LLMs trained on massive markdown. Rho is a markdown superset — default LLM markdown ability + a few DSL rules = immediately usable.

3. Errors degrade gracefully

LLM-generated Rho, even when wrong, falls back to a code-block literal at worst — readers still see the LLM's intent. Won't cause React-style "one quote off, whole page is white."

4. Safety design = host-friendly

Rho has no eval, no arbitrary JS, SVG is auto-sanitized — rendering LLM output directly to readers is safe. No heavy sandbox needed.


What's here

Page Content
Prompt templates 5+ ready-to-use prompts for common generation scenarios
Schema-aware generation Feeding spec / function calling / JSON mode / accuracy boost
Common LLM mistakes & repair LLM-specific common errors + auto-fix patterns

Existing docs (in docs/ root; this guide links them):

Doc Role
AINP protocol — §21 cheat sheet One-page summary of every fence and spec line — the compact thing to paste into a prompt
AINP protocol — §16 For LLM authors Generation discipline, failure recovery, and when not to use the protocol

These two LLM Protocols are for the LLM to read (embed in prompt / system message / fine-tuning data), not for humans — they're tightly compressed so the LLM absorbs all constraints in one go.


Three LLM integration modes

Mode A: direct prompt (simplest)

Embed the LLM Protocol's core rules into the system prompt:

You are a Rho format generator. Rho is markdown extended with:
- Callout: > [!INFO/WARN/ZEN]
- Layout: ```layout grid cols=N + :::card accent=color
- Interact: ```interact + slider/input/template
- ... (extract ~50 lines of core from the LLM Protocol)

When the user requests interactive content, output Rho format.

Best for: single model / single application / trial phase

See Prompt templates.

Mode B: function / tool calling (precise)

Define a generate_rho_doc(...) function schema for the LLM to call:

{
  "name": "generate_rho_doc",
  "description": "Generate a Rho format markdown document",
  "parameters": {
    "type": "object",
    "properties": {
      "title": {"type": "string"},
      "blocks": {
        "type": "array",
        "items": {
          "oneOf": [
            {"type": "object", "properties": {"type": {"const": "callout"}, "callout_type": {"enum": ["INFO", "WARN", "ZEN"]}, "body": {"type": "string"}}},
            {"type": "object", "properties": {"type": {"const": "interact"}, "controls": {...}, "template": {"type": "string"}}},
            ...
          ]
        }
      }
    }
  }
}

LLM outputs JSON → server-side translates to Rho markdown.

Best for: production services / strict quality control / multi-model abstraction

See Schema-aware generation.

Mode C: fine-tune / few-shot (highest quality)

Collect real Rho doc samples + expected task pairs:

  • Few-shot examples embedded in every prompt (simplest)
  • Or fine-tune the base model (most powerful but most expensive)

Best for: large-scale production / specific verticals / commercial products


Step 1: Read the LLM Protocol (CN or EN)
   - 5 minutes; understand Rho syntax constraints
   - Decide which capabilities your app actually needs

Step 2: Try Mode A (direct prompt)
   - Embed ~50 key lines from LLM Protocol into system message
   - Have the LLM try 5 test scenarios
   - Check accuracy

Step 3: Accuracy not enough?
   - Add few-shot examples (Mode C entry)
   - Or switch to Mode B (function calling)

Step 4: Production launch
   - Add LLM output → @rho/md parse validation step
   - Failures fall back to re-prompting

Minimal viable prompt (30-second start)

You are a Rho format generator. Rho is a markdown superset including:

# Callout (emphasis block)
> [!INFO] | [!WARN] | [!ZEN]
> body...

# Interact (interactive)
\```interact
slider name min max initial step    (slider)
input name "default"                 (text input)
select name "opt1" "opt2"           (dropdown)
toggle name true                     (switch)
computed varName = expression        (derived value)
template stl:
  [label] -> [{var}]
  [label2] -> [{(expr):.2f}]
\```

# Layout (multi-column)
\```layout grid cols=N
:::card accent=blue
content
:::
\```

mini DSL: + - * / pow sqrt sin cos pi (NOT JS!)

Task: generate Rho format markdown based on user descriptions.

Put this in your LLM's system prompt → instant basic Rho generation.


See also