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, generate a prompt that includes the options already selected for the command, the available options grouped by category, and the full help text. Give that prompt to an LLM and ask it to propose the smallest command that satisfies your schema and generation goal.
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
If You Are an LLM Agent¶
Use --generate-prompt as an option discovery step before you recommend or run
a final datamodel-codegen command.
- Inspect the user's goal and the input schema when it is available.
- Start from any options the user or existing project already selected.
- Run
datamodel-codegen [known options] --generate-prompt "<goal>". - Preserve current options unless they conflict with the goal or another option.
- Choose the minimal additional options needed for the requested output.
- Return the final CLI command, reasons for each non-obvious option, rejected alternatives, and a verification command.
Use current options in the prompt command so the generated prompt reflects the real configuration you are improving:
datamodel-codegen \
--input openapi.yaml \
--input-file-type openapi \
--output models.py \
--output-model-type pydantic_v2.BaseModel \
--target-python-version 3.12 \
--generate-prompt "Find the minimal options for strict API response models."
A useful answer should keep the command runnable and explain tradeoffs:
- Final command to run
- Why each added or changed option is needed
- Current options that should remain unchanged
- Options considered but rejected, with a short reason
- Verification command, such as
datamodel-codegen ... --checkor a focused generation command against a fixture schema
Structured Output for Tools¶
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 when a tool or agent needs a JSON Schema before
it consumes command output:
datamodel-codegen --output-format-json-schema config
datamodel-codegen --output-format-json-schema generate-prompt
datamodel-codegen --output-format-json-schema generation
datamodel-codegen --output-format-json-schema structured-output
The schema targets are scoped:
config: schema for JSON configuration options such as--aliases,--type-overrides, and--validatorsgenerate-prompt: schema for--generate-prompt --output-format jsongeneration: schema for normal generation with--output-format jsonstructured-output: tagged union schema for all structured command outputs, including prompt, generation, command metadata, and check result payloads
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?"
Strict Pydantic v2 Models¶
datamodel-codegen \
--input openapi.yaml \
--input-file-type openapi \
--output models.py \
--output-model-type pydantic_v2.BaseModel \
--target-python-version 3.12 \
--strict-types str int float bool \
--generate-prompt "Which additional options should I use for strict API response models?" \
| claude -p
Review an Existing Command¶
datamodel-codegen \
--input schema.json \
--output models.py \
--output-model-type pydantic_v2.BaseModel \
--target-python-version 3.11 \
--snake-case-field \
--generate-prompt "Review this command and suggest only necessary option changes." \
| codex exec
Tips¶
- Be specific - Include a clear question to get more relevant recommendations
- Show context - Add your current options so the LLM understands your setup
- Keep options minimal - Prefer the fewest options that satisfy the goal
- Verify output - Run the final command against the target schema or fixture