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.
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:
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:
OpenAI Codex CLI¶
Codex CLI is OpenAI's CLI tool.
Use exec subcommand for non-interactive mode:
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¶
Linux (X11)¶
Linux (Wayland)¶
Windows (PowerShell)¶
WSL2¶
Usage Examples¶
Basic Usage¶
Generate a prompt without a specific question:
JSON Output¶
Generate structured option metadata for automated tools:
With a Question¶
Include your specific question in the prompt:
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¶
- Be specific - Include a clear question to get more relevant recommendations
- Show context - Add your current options so the LLM understands your setup
- Iterate - Use the suggestions, then ask follow-up questions if needed