This prompt is designed for support engineers, CLI maintainers, and platform teams who need to build a structured, searchable catalog of every error message a command-line tool can emit. The primary job-to-be-done is transforming raw error strings, source code, and help text into a machine-readable reference that maps each error to its root cause, affected flags, related exit codes, and actionable resolution steps. The ideal user is someone who owns the support or documentation experience for a CLI tool and needs to ensure that every possible failure mode is documented, discoverable, and linked to a clear remediation path.
Prompt
CLI Error Message Catalog Generation Prompt

When to Use This Prompt
Define the job-to-be-done, the ideal user, required context, and when not to use this prompt for generating a CLI error message catalog.
Use this prompt when you have access to the CLI's source code, can run the binary to trigger error states, or have a comprehensive list of error strings from logs. The prompt expects a [CONTEXT] that includes the raw error text, relevant source code snippets, and any existing documentation. It is most effective for CLIs with a finite, enumerable set of error messages—typically those that use explicit error codes, structured error types, or well-defined exit code conventions. The output is a structured catalog entry, not a narrative troubleshooting guide; it is meant to be ingested by a support knowledge base, a --explain-error command, or an internal troubleshooting tool.
Do not use this prompt for generating user-facing troubleshooting prose directly. It is not designed to write tutorials, FAQs, or conversational support scripts. Avoid using it when the CLI's error messages are dynamically generated from external services, as the catalog will quickly become stale without a live integration. This prompt is also a poor fit for CLIs that produce vague, unstructured error output without distinct error identifiers—in those cases, the source code itself must be improved before a meaningful catalog can be generated. Finally, if the goal is to fix the errors rather than document them, this is the wrong tool; pair this catalog with a separate prompt for error message improvement.
Before running this prompt, ensure you have a complete inventory of error strings. A common failure mode is feeding the prompt an incomplete list, which produces a catalog with dangerous gaps. After generation, you must validate the catalog by cross-referencing it against error strings extracted directly from the source code. The companion evaluation harness should flag any error message found in the source that is missing from the catalog, and it should test a sample of resolution steps against a live CLI environment to confirm they actually resolve the error. Human review is required for any resolution step that involves destructive actions, such as data cleanup commands or configuration resets.
Use Case Fit
Where the CLI Error Message Catalog Generation Prompt works well and where it introduces operational risk. Use these cards to decide whether this prompt fits your current documentation pipeline.
Good Fit: Source-Accessible CLI Tools
Use when: you have direct access to the CLI source code, binary introspection tools, or structured error definition files. The prompt can map error strings to code paths, exit codes, and resolution steps with high accuracy. Guardrail: always ground the catalog against a grep or AST parse of the actual error-emitting code to catch missing entries.
Bad Fit: Closed-Source or External CLIs
Avoid when: the CLI is a third-party binary with no source access and limited documentation. The model will hallucinate plausible error messages, exit codes, and resolution steps that do not exist in the actual tool. Guardrail: restrict use to CLIs where you can verify every catalog entry against observed behavior or source truth.
Required Inputs
What you need: source code or error definition files, --help output, exit code documentation, and a list of all subcommands. Without these, the catalog will have gaps and fabricated resolution steps. Guardrail: provide a structured input manifest listing every error-emitting function, file path, and line range before running the prompt.
Operational Risk: Stale Resolution Steps
What to watch: resolution steps in the catalog may reference commands, flags, or config paths that have changed or been removed. Users following stale guidance can cause further errors. Guardrail: version-lock the catalog to a specific CLI release and run a validation harness that executes each resolution command against that version.
Operational Risk: Incomplete Error Coverage
What to watch: the prompt may miss error messages emitted in rarely-triggered code paths, dynamic error strings, or errors from linked libraries. Support engineers will encounter undocumented errors in production. Guardrail: implement a coverage checker that diffs the catalog against all string literals in error-emitting functions and flags gaps for manual review.
When to Escalate to Human Review
What to watch: errors involving data loss, security violations, authentication failures, or irreversible operations require precise resolution language. A hallucinated step could cause real harm. Guardrail: flag any catalog entry with severity critical or security for mandatory human review before publication, and add a reviewed_by field to the schema.
Copy-Ready Prompt Template
A reusable prompt template with square-bracket placeholders for generating a structured CLI error message catalog.
This prompt template is the core instruction set for generating a structured, searchable catalog of every error message a CLI tool can emit. It is designed to be copied directly into your AI harness, with placeholders that you replace with your specific CLI's source code, documentation, and output constraints. The template forces the model to map error strings to their root causes, affected flags, resolution steps, and related exit codes, producing a machine-readable output that can be ingested by a support knowledge base or a diagnostic tool.
textYou are an expert CLI support engineer and technical writer. Your task is to generate a complete, structured error message catalog for a command-line interface tool. Analyze the provided [SOURCE_CODE] and [HELP_TEXT_OUTPUT] to identify every possible error message the CLI can emit. For each unique error message, produce a structured record that includes the error string, its root cause, the affected flags or subcommands, a clear resolution step, and the associated exit code. [CONSTRAINTS] - Do not invent error messages. Only catalog messages that are explicitly defined in the provided source code or help text. - If an error message is constructed dynamically with variables, represent the variable part with a placeholder like <variable_name>. - For each error, the resolution step must be a single, actionable instruction that a user can execute. - Group related errors by the component or subcommand that triggers them. [OUTPUT_SCHEMA] Return a single JSON object with a key "error_catalog" containing an array of error objects. Each object must have the following fields: - "error_id": A unique slug for the error (e.g., "auth_token_expired"). - "error_pattern": The exact error string or a regex pattern if the message is dynamic. - "exit_code": The integer exit code associated with this error. - "component": The subcommand, flag, or module that triggers this error. - "root_cause": A concise explanation of why this error occurs. - "affected_flags": An array of flag names (long form, e.g., ["--token", "--profile"]) that are relevant to this error. - "resolution_step": A single, direct instruction for the user to resolve the error. - "related_errors": An array of error_id strings for other errors that commonly occur alongside or as a result of this one. [EXAMPLES] Input Source Code Snippet: if token == "" { return fmt.Errorf("authentication failed: token is empty") } Output Record: { "error_id": "auth_token_empty", "error_pattern": "authentication failed: token is empty", "exit_code": 1, "component": "auth", "root_cause": "The --token flag was not provided or was set to an empty string.", "affected_flags": ["--token"], "resolution_step": "Run 'cli-tool login' to generate a new token, or set the --token flag with a valid value.", "related_errors": ["auth_token_expired", "auth_insufficient_scopes"] } [RISK_LEVEL] This output will be used to build a customer-facing troubleshooting guide. Inaccurate resolution steps can lead to user frustration and data loss. All resolution steps must be validated against the source code logic before publication.
To adapt this template, replace the [SOURCE_CODE] and [HELP_TEXT_OUTPUT] placeholders with the actual files or text dumps from your CLI project. If your CLI is written in a language other than Go, adjust the example in the prompt to match your language's error-raising syntax to improve model accuracy. The [OUTPUT_SCHEMA] is a strong constraint, but you should modify the field definitions to match your internal support taxonomy. Before integrating this prompt into a production pipeline, implement a validation step that parses the JSON output and checks for missing exit codes or error patterns that exist in the source but are absent from the catalog. This prompt is not a substitute for a human review of resolution steps, especially for errors that can cause data loss or irreversible state changes.
Prompt Variables
Required and optional inputs for the CLI Error Message Catalog Generation Prompt. Each placeholder must be populated before the prompt is sent to the model. Validation notes describe how to check that the input is complete and correctly formatted before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[CLI_SOURCE_CODE] | Path or inline content of the CLI source files to scan for error message definitions | src/commands/install.go, src/errors/panic_handler.rs | Parse check: verify file paths exist and are readable. Content must include error constructors, throw statements, or exit code assignments. |
[CLI_BINARY_PATH] | Path to the compiled CLI binary for dynamic error extraction via --help or dry-run | /usr/local/bin/my-cli | Parse check: confirm binary exists and is executable. Run |
[ERROR_EXTRACTION_METHOD] | Strategy for locating error messages: static analysis, dynamic execution, or both | static_and_dynamic | Enum check: must be one of |
[TARGET_ERROR_CATEGORIES] | List of error categories to include or exclude from the catalog | ["network", "permission", "parse", "validation"] | Schema check: must be a JSON array of strings. Empty array means all categories. Validate against known error category constants in source if available. |
[OUTPUT_SCHEMA] | Desired JSON schema for each error catalog entry | {"error_string": "...", "exit_code": 1, "cause": "...", "affected_flags": ["--config"], "resolution_steps": ["..."]} | Schema check: must be valid JSON Schema or example object. Confirm required fields include error_string, cause, and resolution_steps at minimum. |
[EXIT_CODE_MAPPING] | Reference table mapping numeric exit codes to error categories already documented | {"1": "general_error", "2": "parse_error", "64": "usage_error"} | Schema check: must be a JSON object with numeric string keys. Validate exit codes against sysexits.h or project conventions. Null allowed if no mapping exists. |
[KNOWN_FALSE_POSITIVES] | List of error-like strings in source that are not user-facing errors | ["TODO: handle error", "debug log: connection failed"] | Parse check: must be a JSON array of strings. Review against source to confirm these are intentionally excluded. Null allowed if no known false positives exist. |
Implementation Harness Notes
How to wire the CLI Error Message Catalog Generation Prompt into a reliable documentation pipeline with validation, source grounding, and human review.
This prompt is designed to be one step in a documentation generation pipeline, not a standalone chat interaction. The primary input is a raw extraction of error-producing code paths from your CLI source, typically gathered by a static analysis script that identifies fmt.Errorf, log.Fatal, return err, or equivalent patterns in your language. The prompt's job is to transform that raw list into a structured, searchable catalog. The output should be a JSON array of error objects, each containing the error string, cause, affected flags, resolution steps, and exit code. This structured output is then ingested by your documentation site generator, support knowledge base, or a CLI --explain-error lookup tool.
Validation and Grounding: The most critical failure mode is an error message existing in the source code but missing from the generated catalog. To prevent this, the harness must perform a completeness check: count the number of error-producing statements in the source extraction and compare it to the number of entries in the model's output. A second validation pass should use a separate LLM call or a deterministic script to verify that each resolution step references real commands or configuration options that exist in the current CLI version. For high-reliability environments, implement a human-in-the-loop review queue that flags any error message with a severity of CRITICAL or FATAL for manual approval before the catalog is published.
Model Choice and Retries: Use a model with strong JSON mode and large context windows, such as claude-sonnet-4-20250514 or gpt-4o, as the source extraction can be lengthy. Implement a retry strategy with exponential backoff for schema validation failures. If the initial output fails JSON schema validation, feed the raw output and the validation errors back into the model with a repair prompt. Log every generation attempt, including the prompt template version, model used, and validation pass/fail status, to create an audit trail. Avoid using this prompt for real-time error explanation in a live CLI session; instead, pre-generate the catalog and serve it from a static file or database for low-latency lookups.
Expected Output Contract
Define the exact shape of a single error catalog entry. Use this contract to validate the model's output before ingestion into a searchable catalog or ticketing system.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
error_id | string (slug) | Matches pattern | |
error_message_pattern | string (regex-safe) | Must compile as a valid regex. Test against at least 3 known raw error strings from source. | |
exit_code | integer or null | Must be a non-negative integer or null. If null, validate that no exit code is set in source. | |
affected_flags | array of strings | Each string must match a documented flag or subcommand name. Empty array allowed. | |
root_cause_category | enum string | Must be one of: [INPUT_VALIDATION, NETWORK, AUTH, FILE_IO, CONFIG, DEPENDENCY, INTERNAL, UNKNOWN]. | |
resolution_steps | array of strings | Minimum 1 step. Each step must be a complete imperative sentence. Test first step for executability. | |
source_location | string (file:line) | Must match pattern | |
severity | enum string | Must be one of: [FATAL, ERROR, WARNING, INFO]. Must align with exit code severity conventions. |
Common Failure Modes
When generating a CLI error message catalog, these failures can silently degrade the catalog's usefulness or introduce inaccuracies. Each card identifies a specific risk and the guardrail to prevent it.
Incomplete Error Coverage
Risk: The prompt misses error strings hidden in library code, dependencies, or OS-level calls, leading to an incomplete catalog. Guardrail: Pair the prompt with a static analysis tool that scans source code for all throw, exit(), and fmt.Errorf calls. Cross-reference the prompt's output against this list to flag missing entries.
Hallucinated Resolution Steps
Risk: The model invents plausible but incorrect or destructive recovery commands (e.g., suggesting --force where it causes data loss). Guardrail: Require the prompt to cite the source file and line number for each resolution step. Implement a validation harness that executes the suggested commands in a sandboxed environment to verify they resolve the error without side effects.
Inconsistent Error-to-Cause Mapping
Risk: The same underlying cause (e.g., network timeout) is mapped to different resolution steps across multiple error messages, confusing users and support staff. Guardrail: Add a post-generation normalization step. Use a secondary prompt or script to group errors by root cause and flag any group with inconsistent resolution advice for human review.
Stale Catalog Drift
Risk: The catalog becomes outdated as the CLI codebase evolves, with new errors added or old messages changed. Guardrail: Embed the catalog generation prompt into a CI/CD pipeline. Run it on every new release tag and use a diffing script to generate a change report. Flag any new, removed, or modified error strings for immediate review.
Ambiguous Exit Code Documentation
Risk: The prompt misattributes an exit code to the wrong error or fails to document exit codes that are set by the OS or runtime, not the application logic. Guardrail: Provide the prompt with a separate, verified exit code reference as a grounding document. Instruct it to only map exit codes explicitly found in the provided source, marking any unknown codes as UNKNOWN for manual investigation.
Evaluation Rubric
Criteria for testing the quality of a generated CLI error message catalog before shipping it to support engineers or end users. Each row defines a pass standard, a failure signal, and a concrete test method.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Error Message Coverage | Catalog contains entries for 100% of unique error strings found in the source code's error-returning paths. | A grep or AST scan of the source finds error strings missing from the catalog's [ERROR_STRING] field. | Automated diff: extract all string literals passed to error constructors in source; compare against the set of [ERROR_STRING] values in the output JSON. |
Exit Code Accuracy | Every catalog entry's [EXIT_CODE] matches the actual exit code the CLI returns for that error condition. | A manual or automated run of the CLI for a sampled error condition produces an exit code different from the catalog entry. | Integration test: trigger a random sample of 10 documented error conditions; assert the process exit code equals the catalog's [EXIT_CODE]. |
Affected Flag Mapping | The [AFFECTED_FLAGS] field correctly lists all CLI flags whose misuse triggers the error, or is null if no flag is involved. | A flag documented as causing the error does not trigger it when used incorrectly, or a flag that triggers the error is missing from the list. | Flag injection test: for each entry with non-null [AFFECTED_FLAGS], run the CLI with each flag in an invalid state and assert the error string matches. |
Resolution Step Validity | Each step in the [RESOLUTION_STEPS] array, when executed in order, resolves the error or advances the user to a state where the command succeeds. | Following the documented steps does not clear the error, introduces a new error, or references non-existent commands or flags. | Manual review by a subject-matter expert for a random sample of 5 entries; automated check that no step references undefined flags or subcommands. |
Structured Output Schema Compliance | The generated JSON catalog strictly conforms to the defined [OUTPUT_SCHEMA] with all required fields present and correctly typed. | The output fails JSON Schema validation; required fields like [ERROR_STRING] or [EXIT_CODE] are missing or null. | Automated validation: pipe the model's output through a JSON Schema validator configured with the expected schema before accepting the file. |
Cause Description Grounding | The [CAUSE] field accurately describes the programmatic condition that raises the error, without hallucinating internal logic. | The [CAUSE] description contradicts the source code logic, mentions non-existent functions, or fabricates a plausible but incorrect reason. | Spot-check: for 3 entries, trace the error string back to the exact source code location and verify the [CAUSE] description matches the conditional logic. |
No Hallucinated Errors | The catalog contains zero entries for error messages that do not exist in the CLI's source code or binary. | The output includes a plausible-sounding error string that cannot be found anywhere in the codebase or triggered via CLI usage. | Fuzzy string match: for every [ERROR_STRING] in the catalog, require an exact match in the source code or a successful trigger via a fuzz test. |
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 single CLI binary and a small sample of error strings. Skip strict schema validation and focus on getting a first-pass catalog with error text, likely cause, and a suggested resolution step. Accept markdown table output initially.
Prompt modification
Remove the [OUTPUT_SCHEMA] constraint and replace it with: Return a markdown table with columns: Error Message, Probable Cause, Affected Flag/Subcommand, Resolution Step.
Watch for
- Missing error messages that only appear in edge-case code paths
- Resolution steps that are too vague to execute
- Exit codes not mapped to error strings

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