Skip to content

LLM Integration

The --generate-prompt option generates a formatted prompt that you can use to consult Large Language Models (LLMs) about datamodel-code-generator CLI options.

Overview

When you're unsure which CLI options to use for your specific use case, you can generate a prompt containing all available options and their descriptions, then ask an LLM for recommendations.

datamodel-codegen --generate-prompt "How do I generate strict Pydantic v2 models?"

The generated prompt includes:

  • Your question (if provided)
  • Current CLI options you've specified
  • All options organized by category with descriptions
  • Full help text for reference

Use --output-format json when an LLM agent or tool should consume structured option metadata instead of Markdown:

datamodel-codegen --generate-prompt "How do I generate strict Pydantic v2 models?" --output-format json

The JSON payload includes the user question, current options, options grouped by category, full option metadata from argparse, and help text without ANSI color codes.

Use --output-format-json-schema generate-prompt when a tool or agent needs the schema for the structured payload:

datamodel-codegen --output-format-json-schema generate-prompt

CLI LLM Tools

Pipe the generated prompt directly to CLI-based LLM tools:

Claude Code

Claude Code is Anthropic's official CLI tool. Use -p flag for non-interactive (pipe) mode:

datamodel-codegen --generate-prompt "Best options for API response models?" | claude -p

OpenAI Codex CLI

Codex CLI is OpenAI's CLI tool. Use exec subcommand for non-interactive mode:

datamodel-codegen --generate-prompt "How to handle nullable fields?" | codex exec

For agents that can inspect structured input, prefer JSON:

datamodel-codegen --generate-prompt "How to handle nullable fields?" --output-format json | codex exec

Other CLI Tools

Other popular LLM CLI tools that accept stdin:

Tool Command Repository
llm \| llm simonw/llm
aichat \| aichat sigoden/aichat
sgpt \| sgpt TheR1D/shell_gpt
mods \| mods charmbracelet/mods

Check each tool's documentation for specific usage and options.

Web LLM Chat Services

Copy the prompt to clipboard, then paste into your preferred web-based LLM chat:

macOS

datamodel-codegen --generate-prompt | pbcopy

Linux (X11)

datamodel-codegen --generate-prompt | xclip -selection clipboard

Linux (Wayland)

datamodel-codegen --generate-prompt | wl-copy

Windows (PowerShell)

datamodel-codegen --generate-prompt | Set-Clipboard

WSL2

datamodel-codegen --generate-prompt | clip.exe

Usage Examples

Basic Usage

Generate a prompt without a specific question:

datamodel-codegen --generate-prompt

JSON Output

Generate structured option metadata for automated tools:

datamodel-codegen --generate-prompt "Find the minimal strict-model options." --output-format json

With a Question

Include your specific question in the prompt:

datamodel-codegen --generate-prompt "What options should I use for GraphQL schema?"

With Current Options

Show your current configuration and ask for improvements:

datamodel-codegen \
    --input schema.json \
    --output-model-type pydantic_v2.BaseModel \
    --use-annotated \
    --generate-prompt "Are there any other options I should consider?"

Pipe to Claude with Options

datamodel-codegen \
    --input openapi.yaml \
    --output-model-type dataclasses.dataclass \
    --generate-prompt "How can I add JSON serialization support?" \
    | claude -p

Tips

  1. Be specific - Include a clear question to get more relevant recommendations
  2. Show context - Add your current options so the LLM understands your setup
  3. Iterate - Use the suggestions, then ask follow-up questions if needed