Generating scientific schematics with an AI image model
Adapted from the MarkItDown skill in K-Dense-AI/claude-scientific-skills (MIT). See THIRD_PARTY_NOTICES.md.
Generate publication-style schematic images (flowcharts, block diagrams, architecture figures) from a text description. The AI variant runs an iterative quality loop: generate, have a vision model critique the result against the document type, regenerate until the quality threshold or the iteration cap is hit.
Requirements
OPENROUTER_API_KEYin the environment (both scripts talk to OpenRouter).httpx2for the AI script: run it withuv run, which reads the script's PEP 723 block and fetches the dependency. Plainpython3only works if httpx2 is already installed. The wrapper script imports only stdlib, but it re-launches the AI script with the SAME interpreter (sys.executable), so it needshttpx2just as much - run it underuv run --with httpx2too, or the child exits 1 on its first import.
Usage
# AI generation with quality-review loop
uv run scripts/generate_schematic_ai.py "CONSORT participant flow for a two-arm RCT" -o flow.png
uv run scripts/generate_schematic_ai.py "Neural network architecture diagram" -o arch.png --iterations 2
uv run scripts/generate_schematic_ai.py "Simple block diagram" -o diagram.png --doc-type poster
# Wrapper: same quality-review loop, with the iteration cap clamped to 2
uv run --with httpx2 scripts/generate_schematic.py "Data pipeline overview" -o pipeline.png
--doc-type tunes the acceptance threshold (a poster tolerates less detail than a paper
figure); --iterations caps the regenerate loop.
Common mistakes
- Expecting deterministic output - image models vary run to run; keep the prompt specific (name the boxes, arrows, and labels you need) and review the result yourself.
- Using this for graphs that should be code-rendered - reproducible plots and graphs belong in graphviz/matplotlib, not an image model; this skill is for illustrative schematics.
- Committing the generated image without checking the labels - vision-model review catches layout problems, not domain wording.
- Running without
OPENROUTER_API_KEY- both scripts fail fast; set it in the environment, never on the command line.