This prompt is designed for CLI tool maintainers, platform engineers, and technical writers who need to convert raw --help output into a structured, machine-readable JSON catalog of every flag, option, and argument. The primary job-to-be-done is automating the tedious and error-prone process of manually transcribing help text into configuration schemas, API reference docs, or UI form fields. The ideal user has access to the exact help text string from a specific version of a CLI tool and requires a complete, validated schema that captures long/short flags, data types, default values, whether a flag is required, and any mutual exclusion groups.
Prompt
CLI Flag Extraction Prompt from Help Text

When to Use This Prompt
Define the job, the user, and the boundaries for extracting structured CLI flag catalogs from raw help text.
You should use this prompt when you have a stable, complete block of help text and need a deterministic, structured extraction. It is particularly effective when integrated into a CI/CD pipeline to detect drift between the implemented CLI and its documentation. However, do not use this prompt when the help text is truncated, dynamically generated based on user permissions, or contains locale-specific formatting that the model cannot reliably parse. This prompt is not a substitute for parsing the source code directly when 100% accuracy is required for safety-critical systems; in such cases, use it as a first-pass generator that must be followed by a strict source-code introspection validation harness.
Before executing this prompt, ensure the input help text is complete and unaltered. After extraction, you must validate the output JSON against the original text to confirm no flags were missed and that mutual exclusion rules are correctly represented. The next step is to wire this prompt into an automated harness that compares the extracted schema against a known-good specification or the binary's actual behavior, flagging any discrepancies for human review before the schema is published or used in production tooling.
Use Case Fit
Where the CLI Flag Extraction Prompt delivers reliable structured output and where it introduces operational risk.
Good Fit: Structured Flag Catalogs
Use when: you need to convert raw --help output into a strict JSON schema for downstream tooling, CI/CD pipelines, or automated documentation generation. The prompt excels at identifying long/short flags, types, defaults, and required status when the help text follows standard conventions (e.g., docopt, argparse, cobra). Guardrail: Provide an explicit JSON schema in the prompt to enforce field-level type consistency.
Bad Fit: Non-Standard or Localized Help Text
Avoid when: the help text uses heavily customized formatting, non-English languages, or dynamic content generated at runtime. The model may hallucinate flags or misinterpret positional arguments when the structure deviates from common CLI frameworks. Guardrail: Pre-process the help text with a regex-based sanity check for known patterns before sending it to the model.
Required Inputs: Canonical Help Text
Risk: Stale or truncated help text produces an incomplete flag catalog that silently omits deprecated or hidden flags. Guardrail: Always capture the full output of [COMMAND] --help at the exact version being documented. Implement a CI check that compares the extracted flag count against a known baseline and fails on mismatch.
Operational Risk: Mutual Exclusion Blindness
Risk: The model may extract individual flags correctly but miss mutual exclusion groups or dependent flag relationships, leading to invalid command suggestions in downstream tools. Guardrail: After extraction, run a deterministic validator that checks for known conflict rules (e.g., --json and --table cannot coexist) and flags missing constraints for human review.
Operational Risk: Drift Over Versions
Risk: The extracted schema becomes stale when the CLI adds, removes, or renames flags in a new release. Guardrail: Version-pin the extracted schema artifact alongside the CLI version. Automate a weekly drift detection job that re-runs the extraction prompt and diffs the output against the stored schema, alerting on any changes.
Bad Fit: Complex Nested Subcommands
Risk: A single prompt attempting to extract flags from a deeply nested subcommand tree often produces truncated or merged results. Guardrail: Decompose the task. Run the extraction prompt once per subcommand, providing only that subcommand's help text. Assemble the full tree in the application layer.
Copy-Ready Prompt Template
A reusable prompt that extracts every flag, option, and argument from raw CLI help text into a structured JSON schema.
This prompt template is designed to be dropped directly into your application code. It takes raw --help output as input and produces a structured JSON catalog of all flags, options, and arguments. The template uses square-bracket placeholders that you replace with your specific CLI context, output requirements, and constraints before sending to the model.
textYou are a CLI documentation parser. Your task is to extract every flag, option, and positional argument from the provided help text into a structured JSON schema. [CONTEXT] The CLI tool is named [TOOL_NAME]. The help text was generated by running: [HELP_COMMAND] [INPUT]
[HELP_TEXT]
code[OUTPUT_SCHEMA] Return a JSON object with the following structure: { "tool_name": "string", "help_command": "string", "flags": [ { "long_flag": "string (e.g., --verbose)", "short_flag": "string or null (e.g., -v)", "type": "string (boolean, string, integer, count, array)", "default": "string or null", "required": boolean, "description": "string", "value_hint": "string or null (e.g., PATH, LEVEL, NAME)", "mutually_exclusive_with": ["string (long_flag names)"], "deprecated": boolean, "deprecation_message": "string or null" } ], "positional_args": [ { "name": "string", "required": boolean, "multiple": boolean, "description": "string", "value_hint": "string or null" } ], "subcommands": [ { "name": "string", "description": "string", "aliases": ["string"] } ] } [CONSTRAINTS] 1. Extract EVERY flag mentioned in the help text. Do not skip any. 2. For boolean flags, set type to "boolean" and default to "false" unless the help text explicitly states otherwise. 3. If a flag accepts a value, set type to "string" unless the help text specifies a different type (integer, count). 4. Infer mutually_exclusive_with groups from phrases like "cannot be used with" or "mutually exclusive with." 5. Mark flags as deprecated if the help text contains words like "deprecated," "will be removed," or "use [alternative] instead." 6. If the help text does not specify a short flag, set short_flag to null. 7. For positional arguments, set multiple to true if the help text indicates the argument can accept multiple values (e.g., "FILE..." or "[FILES]..."). 8. If no subcommands are present, return an empty array. 9. Preserve the exact description text from the help output. Do not paraphrase. 10. If you are uncertain about any field, include an "uncertainty_note" field in that object explaining what is ambiguous. [EXAMPLES] Input help text:
Usage: mycli [OPTIONS] INPUT [OUTPUT]
Options: -v, --verbose Enable verbose output -o, --output FILE Write output to FILE instead of stdout -q, --quiet Suppress all output --retries N Number of retries (default: 3) --no-color Disable colored output (deprecated, use --color=never)
codeExpected output: { "tool_name": "mycli", "help_command": "mycli --help", "flags": [ { "long_flag": "--verbose", "short_flag": "-v", "type": "boolean", "default": "false", "required": false, "description": "Enable verbose output", "value_hint": null, "mutually_exclusive_with": [], "deprecated": false, "deprecation_message": null }, { "long_flag": "--output", "short_flag": "-o", "type": "string", "default": null, "required": false, "description": "Write output to FILE instead of stdout", "value_hint": "FILE", "mutually_exclusive_with": [], "deprecated": false, "deprecation_message": null }, { "long_flag": "--quiet", "short_flag": "-q", "type": "boolean", "default": "false", "required": false, "description": "Suppress all output", "value_hint": null, "mutually_exclusive_with": ["--verbose"], "deprecated": false, "deprecation_message": null }, { "long_flag": "--retries", "short_flag": null, "type": "integer", "default": "3", "required": false, "description": "Number of retries (default: 3)", "value_hint": "N", "mutually_exclusive_with": [], "deprecated": false, "deprecation_message": null }, { "long_flag": "--no-color", "short_flag": null, "type": "boolean", "default": "false", "required": false, "description": "Disable colored output (deprecated, use --color=never)", "value_hint": null, "mutually_exclusive_with": [], "deprecated": true, "deprecation_message": "use --color=never" } ], "positional_args": [ { "name": "INPUT", "required": true, "multiple": false, "description": "INPUT", "value_hint": null }, { "name": "OUTPUT", "required": false, "multiple": false, "description": "OUTPUT", "value_hint": null } ], "subcommands": [] } [RISK_LEVEL] Medium. Incorrect flag extraction can break downstream tooling that relies on accurate CLI documentation. Always validate the extracted schema against the original help text and test flag combinations for mutual exclusion conflicts.
To adapt this template for your CLI tool, replace the placeholders as follows: [TOOL_NAME] with the name of your CLI binary, [HELP_COMMAND] with the exact command used to generate the help text (e.g., tool --help or tool subcommand --help), and [HELP_TEXT] with the raw help output. If your CLI uses non-standard help formatting, add additional constraints to the [CONSTRAINTS] section describing your specific patterns. For CLIs with deeply nested subcommands, run this prompt once per subcommand and merge the results, using the subcommands array to track the hierarchy. Always validate the extracted schema by comparing the total flag count against the original help text and by testing that mutually exclusive groups do not contain overlapping flags.
Prompt Variables
Required inputs for the CLI flag extraction prompt. Each placeholder must be populated before the prompt is sent. Validation notes describe how to confirm the input is well-formed before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[HELP_TEXT] | Raw --help output from the CLI tool to parse | docker run --help | Must be non-empty string. Check for truncated output (look for terminal width artifacts). Verify the help text matches the target CLI version. |
[TOOL_NAME] | Canonical name of the CLI tool for schema metadata | docker | Must match the binary invocation name exactly. Validate against the tool's actual binary name to prevent downstream catalog mismatches. |
[TOOL_VERSION] | Semantic version of the CLI tool being documented | 27.3.1 | Must be a valid semver string. Cross-check against --version output. Required for downstream consumers to know which version the flag catalog describes. |
[OUTPUT_SCHEMA] | JSON Schema or type definition the extracted flags must conform to | See playbook output contract | Must be a valid JSON Schema object. Validate with a schema validator before passing. Schema must include required fields: long_flag, short_flag, type, default, required, mutually_exclusive_with. |
[FLAG_TYPE_ENUM] | Allowed flag types the model may assign | ["string", "boolean", "integer", "float", "array", "count"] | Must be a valid JSON array of strings. Restrict to types actually supported by the CLI's argument parser. Boolean flags should not accept values; count flags increment. |
[MUTUAL_EXCLUSION_HINT] | Known mutual exclusion groups to guide extraction accuracy | ["--detach", "--interactive"] | Optional. If provided, must be a JSON array of string arrays. Validate that each group contains flags actually present in [HELP_TEXT]. Null allowed if no groups are known in advance. |
[DEPRECATION_PATTERNS] | Regex or string patterns that signal a deprecated flag in help text | ["deprecated", "will be removed", "use --"] | Must be a JSON array of strings. Test each pattern against known deprecated flags in the help text to confirm they match. Adjust patterns if false positives occur on non-deprecation language. |
Implementation Harness Notes
How to wire the CLI flag extraction prompt into a reliable documentation pipeline with validation, retries, and drift detection.
The CLI flag extraction prompt is designed to be called programmatically as part of a documentation generation pipeline, not as a one-off chat interaction. The core integration pattern is: capture raw --help output from the target CLI binary (ensuring you capture both stdout and stderr, as some tools emit help text to stderr), pass it to the model with the extraction prompt, validate the returned JSON schema, and then feed the structured flag catalog into your documentation site generator, man page compiler, or API reference system. The harness must treat the model output as a draft that requires mechanical verification before publication.
Build the harness with these concrete checks. Schema validation: validate the returned JSON against a strict schema that requires long_flag, short_flag, type, default, required, description, and mutual_exclusion_group fields for every flag object. Reject any output missing required fields or containing flags not present in the original help text. Flag completeness check: parse the original help text with a regex-based flag extractor (matching patterns like --flag, -f, --flag=VALUE) and compare the set of extracted flags against the model's output. Flag any missing or hallucinated flags for human review. Mutual exclusion validation: for every mutual exclusion group the model identifies, verify that the group members actually appear together in the original help text (look for phrases like "cannot be used with", "mutually exclusive", or grouped option blocks). Default value verification: when the help text explicitly states a default, confirm the model captured it correctly. When the help text is silent on defaults, the model should use null rather than inventing a value. Retry logic: if schema validation fails, retry once with the validation errors appended to the prompt as feedback. If the second attempt also fails, escalate to a human review queue with the original help text, the failed output, and the specific validation errors.
For production use, implement a drift detection loop. Schedule a periodic job (weekly or on each release) that re-extracts help text from the latest CLI binary, runs the extraction prompt, and diffs the new flag catalog against the previously published version. Flag any additions, removals, or description changes for review. This catches undocumented flags, removed flags still in docs, and stale descriptions before users report them. Log every extraction run with the CLI version, help text hash, model version, and validation results. Store these artifacts for auditability. Avoid wiring the prompt directly into a CI/CD publish step without human approval—flag documentation changes should follow the same review process as code changes, especially for breaking flag removals or semantic changes to existing flags.
Expected Output Contract
Define the exact JSON schema the prompt must return. Each row specifies a field, its type, whether it is required, and a concrete validation rule that can be checked programmatically after extraction.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
flags | Array of objects | Must be a non-empty array. If no flags are found, return an empty array []. | |
flags[].long_name | String or null | Must match the pattern '--[a-z0-9-]+' if present. Must be null if only a short flag exists. | |
flags[].short_name | String or null | Must match the pattern '-[a-zA-Z0-9]' if present. Must be null if only a long flag exists. | |
flags[].type | String (enum) | Must be one of: 'string', 'integer', 'boolean', 'count', 'array'. Default to 'boolean' if no argument is accepted. | |
flags[].default | String, Number, Boolean, or null | Must be present. Use null if no default is documented. Type must match the 'type' field. | |
flags[].required | Boolean | Must be true or false. Check against explicit 'Required' or 'Mandatory' language in the help text. | |
flags[].description | String | Must be a non-empty string summarizing the help text for this flag. Cannot be a direct copy-paste if it exceeds 200 characters; summarize instead. | |
flags[].mutual_exclusion_group | String or null | If the flag belongs to a mutually exclusive group, provide the group name. Validate that all flags in the group are documented. Use null if not applicable. |
Common Failure Modes
What breaks first when extracting CLI flags from help text and how to guard against it.
Silent Flag Omission
What to watch: The model skips flags buried in prose descriptions, nested under subcommands, or mentioned only in examples rather than the structured options list. Guardrail: Post-extraction diff against a regex scan of the raw help text for known flag patterns (--[a-z], -[A-Z]). Flag any token matching a flag pattern that is absent from the extracted JSON.
Mutual Exclusion Collapse
What to watch: The model fails to capture --flag-a and --flag-b as mutually exclusive, or incorrectly groups flags that can be combined. Guardrail: After extraction, generate all pairwise combinations of flags marked as mutually exclusive and validate them against the tool's actual parser. A single accepted invalid pair means the exclusion rules are wrong.
Type and Default Hallucination
What to watch: The model invents a default value (`default:
Short Flag Collision
What to watch: The model assigns -v to both --verbose and --version across different subcommands without noting the context-dependent binding. Guardrail: The output schema must key short flags under their parent command path. Validate that no two flags under the same command node share a short flag. Flag any collision for human review.
Deprecation Blind Spot
What to watch: The model treats a deprecated flag as fully supported, omitting the deprecation notice, replacement flag, or removal timeline mentioned in the help text. Guardrail: Scan the raw help text for deprecation keywords (deprecated, removed in, use --instead). Cross-check that every flagged instance maps to a status: "deprecated" entry with a non-empty replaced_by field in the output.
Positional Argument Misclassification
What to watch: The model extracts a positional argument (<input-file>) as an optional flag or vice versa, breaking downstream command construction. Guardrail: Validate the extracted schema against a simple parser that distinguishes [optional] from <required> and --flag from positional tokens in the usage line. Any mismatch between the usage line and the extracted required or arg_type field must be surfaced.
Evaluation Rubric
Use this rubric to test the quality and completeness of the extracted CLI flag schema before integrating it into your documentation pipeline or product harness. Each criterion targets a known failure mode in flag extraction from unstructured help text.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Flag Completeness | Every flag, option, and positional argument present in [HELP_TEXT] appears in the output schema | Output schema is missing flags found in the original help text; flag count mismatch | Diff the set of extracted flag names against a manually verified or regex-parsed list from [HELP_TEXT] |
Short/Long Flag Pairing | Each flag with both a short form (-f) and long form (--file) is represented as a single entry with both aliases | Short and long forms appear as separate, unlinked entries; missing short form for a documented long flag | For each entry, assert that if a long flag exists, its corresponding short flag is in the aliases array and vice versa |
Type Correctness | The type field matches the argument expectation: string for text values, integer for counts, boolean for toggles, array for repeatable flags | A flag documented as accepting a file path is typed as boolean; a repeatable flag is typed as string instead of array | Sample-parse the help text description for type indicators (e.g., 'specify a file', 'enable', 'can be specified multiple times') and assert type alignment |
Default Value Accuracy | The default field matches the documented default in [HELP_TEXT] or is null when no default is stated | A flag with a documented default of '8080' shows null or an incorrect default; a required flag shows a default value | Extract default value claims from help text patterns like '(default: X)' or '[default: X]' and assert exact match |
Required Flag Identification | Flags documented as mandatory or positional arguments marked required have required: true; all others have required: false | A required flag is marked as optional; a purely optional flag is marked as required | Check help text for required indicators (angle brackets, 'REQUIRED', positional absence of brackets) and assert required field matches |
Mutual Exclusion Group Integrity | Flags belonging to a documented mutual exclusion group appear in the same mutual_exclusion_group array with a shared group label | Mutually exclusive flags are listed without a group; a flag appears in multiple conflicting groups; group membership contradicts help text | Parse help text for mutual exclusion signals ('--flag1 and --flag2 are mutually exclusive', 'either --a or --b') and assert group membership and exclusivity |
Deprecation Flagging | Deprecated flags have deprecated: true and include a deprecation_notice string when the help text indicates deprecation | A flag marked as '[deprecated]' or 'Use --new-flag instead' in help text shows deprecated: false or missing deprecation_notice | Scan [HELP_TEXT] for deprecation keywords and assert the deprecated boolean and notice presence for each flagged entry |
Schema Structural Validity | Output is valid JSON that conforms to the declared [OUTPUT_SCHEMA] with no missing required fields per entry | Output fails JSON parse; required fields like name, type, or description are absent; extra unexpected fields break downstream consumers | Validate output against the JSON Schema definition for the flag catalog; reject on parse errors or schema violation |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Use the base prompt with a frontier model and minimal post-processing. Paste raw --help output into [HELP_TEXT] and request JSON output without strict schema enforcement. Accept the first valid JSON response.
Watch for
- Missing short flags when help text uses only long form
- Boolean flags parsed as string types
- Mutual exclusion groups flattened into flat arrays
- Default values extracted as strings instead of typed values

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us