Inferensys

Prompt

CLI Exit Code Troubleshooting Guide Prompt

A practical prompt playbook for using CLI Exit Code Troubleshooting Guide Prompt in production AI workflows.
Wide-angle shot of a modern WeWork open floor plan with creative walls covered in AI system architecture diagrams, product team collaborating in standing desk area with industrial lighting.
PROMPT PLAYBOOK

When to Use This Prompt

Understand the job-to-be-done, required context, and boundaries for the CLI Exit Code Troubleshooting Guide Prompt.

This prompt is designed for support engineers and CLI tool maintainers who need to build a decision-tree troubleshooting guide that maps exit codes and error patterns to diagnostic steps and resolutions. The ideal user has access to a catalog of known exit codes, error messages, and a test environment where they can intentionally trigger error conditions to validate each diagnostic path. The core job-to-be-done is transforming a flat list of error codes into a structured, actionable guide that walks an end user from an error symptom through a series of diagnostic commands to a verified resolution, reducing mean time to recovery for CLI users.

Use this prompt when you have a stable CLI tool with documented or discoverable exit codes and the ability to execute diagnostic commands against a live test harness. The prompt expects you to provide a mapping of exit codes to error patterns, typical stderr output, and the diagnostic commands that can confirm the root cause. The output is a decision-tree guide, not a simple reference table; each branch should lead to a specific resolution step. Do not use this prompt when you lack access to the CLI tool for live testing, when exit codes are not documented or discoverable, or when the troubleshooting requires deep system-level state that cannot be reproduced in a test harness. In those cases, a static error code reference or a manual runbook is more appropriate.

Before using this prompt, gather your raw materials: a complete list of exit codes, example error messages for each, the diagnostic commands that reveal the underlying state, and the resolution commands that fix the issue. The prompt works best when you can validate each diagnostic path against intentionally triggered error conditions. After generating the guide, run a harness that executes each diagnostic command against a known-bad state and confirms that the resolution step restores the system to a working condition. If any path fails validation, iterate on the prompt with more specific error patterns or additional diagnostic steps. Avoid shipping the guide without end-to-end validation of at least the most common error paths.

PRACTICAL GUARDRAILS

Use Case Fit

This prompt generates a decision-tree troubleshooting guide from exit codes and error patterns. It works best when the error surface is known and diagnostic paths are testable. It is not a substitute for live system debugging or root-cause analysis of novel failures.

01

Good Fit: Known Error Catalog

Use when: you have a stable set of exit codes, stderr patterns, and documented recovery steps. The prompt excels at structuring existing knowledge into a decision tree. Guardrail: maintain a canonical error catalog as the source of truth; regenerate the guide when the catalog changes.

02

Bad Fit: Novel or Intermittent Failures

Avoid when: the error is new, intermittent, or caused by external system state the CLI cannot observe. The prompt cannot diagnose unknown failures. Guardrail: route novel failures to a human triage queue and use this prompt only for known error patterns with reproducible triggers.

03

Required Inputs

What you need: a complete exit code list, per-code stderr patterns, diagnostic commands that are safe to run, and verified resolution steps. Guardrail: validate each diagnostic command in a sandbox before including it in the guide. A command that causes data loss or hangs must never appear in a troubleshooting path.

04

Operational Risk: Stale Paths

What to watch: diagnostic commands or resolution steps that worked in a previous CLI version but fail or cause harm in the current version. Guardrail: version-lock the guide to a specific CLI release and run automated harness tests that intentionally trigger each error and verify the documented path resolves it.

05

Operational Risk: Destructive Commands

What to watch: a troubleshooting step that includes rm, truncate, DROP, or credential rotation without confirmation. Guardrail: require human approval gates for any destructive step. The prompt output must flag destructive actions with a requires_approval: true marker and a rollback note.

06

Variant: Self-Service vs. Escalation

Use when: you need separate paths for end-user self-service and L2/L3 support escalation. Guardrail: add a [AUDIENCE] input variable that controls depth, permissions assumed, and whether destructive steps are included. Test both audience variants against the same error catalog.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A complete, copy-ready prompt template for generating a decision-tree troubleshooting guide from CLI exit codes and error messages.

This prompt template is designed to be dropped directly into your AI harness or prompt management system. It instructs the model to act as a senior support engineer and produce a structured troubleshooting guide. The template uses square-bracket placeholders for all dynamic inputs—exit code catalogs, error message lists, diagnostic commands, and output format preferences—so you can populate it programmatically from your CLI's source of truth before each generation run.

code
You are a senior support engineer writing a troubleshooting guide for the [CLI_TOOL_NAME] CLI tool. Your task is to produce a decision-tree guide that maps exit codes and error patterns to diagnostic steps and resolutions.

## Exit Code Reference
[EXIT_CODE_CATALOG]

## Error Message Catalog
[ERROR_MESSAGE_CATALOG]

## Diagnostic Commands Available
[DIAGNOSTIC_COMMANDS]

## Output Requirements
Produce a troubleshooting guide in the following structure:

1. **Symptom Recognition**: For each exit code, describe the user-visible symptoms, including typical stderr output patterns and the context in which the error occurs.

2. **Decision Tree**: Create a branching decision tree that starts with the exit code or error message and guides the user through diagnostic steps. Each node must include:
   - The diagnostic command to run
   - The expected output for a healthy state
   - The output patterns that indicate specific failure modes
   - The next step based on each possible outcome

3. **Resolution Steps**: For each leaf node in the decision tree, provide:
   - The exact commands to run to resolve the issue
   - Verification steps to confirm the resolution worked
   - Rollback or cleanup commands if the resolution fails

4. **Escalation Criteria**: Define when the user should stop self-troubleshooting and escalate to a support engineer, including the exact information to include in the escalation ticket.

## Constraints
- Every diagnostic command must be safe to run in a user environment (no destructive operations without explicit warnings).
- Every resolution step must include a verification command.
- The decision tree must cover every exit code in the provided catalog.
- Use [OUTPUT_FORMAT] for the final guide.
- Flag any exit code or error message that lacks a known resolution with `[UNRESOLVED]` and suggest escalation.

To adapt this template for your own CLI tool, replace the bracketed placeholders with structured data extracted from your build pipeline or source code. [EXIT_CODE_CATALOG] should contain a list of numeric codes, their meanings, and associated error categories. [ERROR_MESSAGE_CATALOG] should map exact error strings to their likely causes. [DIAGNOSTIC_COMMANDS] must be a curated list of safe, read-only commands users can run to inspect state. The [OUTPUT_FORMAT] placeholder lets you specify whether the final guide should be Markdown, HTML, or a structured JSON object for rendering in a support portal. Always validate the generated guide against a golden set of intentionally triggered error conditions before publishing.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the CLI Exit Code Troubleshooting Guide Prompt. Each variable must be populated before the prompt is assembled and sent. Validation notes describe how to verify the input is well-formed before execution.

PlaceholderPurposeExampleValidation Notes

[CLI_TOOL_NAME]

Identifies the CLI tool being documented so the model scopes all troubleshooting guidance to the correct binary.

aws-cli

Must match the exact binary name. Validate with which [CLI_TOOL_NAME] or command -v [CLI_TOOL_NAME]. Reject if the binary is not found on the target system.

[EXIT_CODE_CATALOG]

Provides the complete mapping of numeric exit codes to error categories and stderr patterns. This is the source of truth the model uses to build diagnostic paths.

0: Success, 1: Generic error, 2: Parse error, 3: Auth failure, 4: Network timeout

Parse as JSON array of objects with keys: code, category, stderr_pattern. Validate that every exit code found in source code or --help output is represented. Reject if catalog is empty or missing required keys.

[COMMAND_CONTEXT]

Specifies the exact command or subcommand that produced the error. Narrows the troubleshooting guide to the relevant surface area.

aws s3 cp s3://bucket/file ./local-path

Must be a valid invocation string. Validate by checking that the subcommand path exists in the CLI's subcommand tree. Reject if the command contains unresolved shell variables or unescaped characters.

[STDERR_OUTPUT]

The actual error message or stderr snippet the user received. The model uses this to match against known error patterns and select the correct diagnostic branch.

An error occurred (AccessDenied) when calling the GetObject operation: Access Denied

Must be a non-empty string. Validate that it is not truncated mid-token. If the error message contains PII or secrets, redact before passing. Null allowed only when generating a general reference guide rather than a specific troubleshooting path.

[SYSTEM_CONTEXT]

Describes the operating environment: OS, shell, CLI version, and any relevant configuration. Used to tailor diagnostic commands and resolution steps.

Ubuntu 22.04, bash 5.1, aws-cli v2.13.0, ~/.aws/config present

Parse as key-value pairs. Validate that CLI version is parseable and matches [CLI_TOOL_NAME] --version output. Reject if OS or shell is unspecified when diagnostic commands are platform-specific.

[OUTPUT_FORMAT]

Defines the structure of the generated troubleshooting guide: decision tree, step-by-step walkthrough, or structured reference.

decision-tree

Must be one of: decision-tree, step-by-step, reference-table. Validate against an allowed enum. Reject unrecognized formats. Default to decision-tree if null.

[DIAGNOSTIC_COMMANDS]

A list of diagnostic commands the model is allowed to recommend. Prevents the model from suggesting commands that are unavailable or unsafe in the target environment.

["aws sts get-caller-identity", "aws configure list", "ping -c 3", "curl -I"]

Parse as JSON array of strings. Validate each command against an allowlist or check that it exists on the target system. Reject any command containing destructive operations (rm, drop, delete) unless explicitly approved. Null allowed when generating a generic guide.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the troubleshooting guide prompt into a validated documentation pipeline with error injection, diagnostic verification, and automated completeness checks.

The CLI Exit Code Troubleshooting Guide Prompt is designed to be wired into a documentation generation pipeline with automated validation. The harness must test each diagnostic path against intentionally triggered error conditions to verify that the resolution steps actually resolve the issue. This is not a prompt you run once and publish—it is a prompt you integrate into a CI-like pipeline where every generated decision tree is exercised against a live or containerized CLI environment before it reaches users.

The harness architecture has four layers. First, an Error Injection Layer uses a test environment where each exit code can be reliably triggered—this may involve setting incorrect permissions, providing invalid configs, disconnecting network interfaces, or using fault-injection tools like strace wrappers or filesystem mocks. Second, a Diagnostic Execution Engine walks each path in the generated decision tree, executes the diagnostic commands against the error state, and verifies that the output matches the expected patterns described in the guide. Third, a Resolution Validator follows the resolution steps and confirms the exit code returns to 0 and the tool operates correctly; if a resolution fails, the path is flagged for human review. Fourth, a Completeness Checker compares the exit codes covered in the generated guide against the source-of-truth exit code catalog and flags any exit code that lacks a documented troubleshooting path.

Retry and repair logic is essential. If the model output fails validation—missing exit codes, unresolvable paths, unsafe commands—retry the prompt with the specific failure feedback appended as additional context. After 3 retries, escalate the unresolved paths to a human technical writer rather than looping indefinitely. Log every generated diagnostic path, the harness test result, and any discrepancies between expected and actual command behavior. This log becomes the audit trail for the troubleshooting guide's accuracy and is invaluable when the CLI itself changes and the guide needs updating.

For model choice, prefer a model with strong instruction-following and structured output capabilities. The prompt should be called with a low temperature (0.1–0.3) to maximize consistency across diagnostic paths. If your CLI has more than 20 exit codes, consider splitting the prompt into multiple calls grouped by error category—permission errors, network errors, input validation errors—to keep each generation focused and testable. Always run the harness in an isolated environment; never execute diagnostic commands from an untested guide against production systems.

IMPLEMENTATION TABLE

Expected Output Contract

Schema contract for the CLI exit code troubleshooting guide. Use this table to validate the model's output before it reaches the user or a downstream system. Every field must pass the stated validation rule or trigger a retry or human escalation.

Field or ElementType or FormatRequiredValidation Rule

guide_title

string

Must be a non-empty string that includes the CLI tool name and the phrase 'Troubleshooting Guide'. Parse check: length > 0.

error_catalog

array of objects

Must be a non-empty array. Each object must contain the keys 'exit_code', 'error_pattern', 'symptoms', and 'diagnostic_steps'. Schema check: validate against JSON Schema.

error_catalog[].exit_code

integer or string

Must match a documented exit code for the target CLI tool. If the code is not in the provided [EXIT_CODE_REFERENCE], flag for human review.

error_catalog[].error_pattern

string (regex)

Must be a valid regular expression string that matches the associated stderr output. Parse check: compile the regex in a test harness; fail if invalid.

error_catalog[].symptoms

array of strings

Must contain at least one user-observable symptom. Each string must be a complete sentence. Null or empty array is not allowed.

error_catalog[].diagnostic_steps

array of objects

Each step object must have 'order' (integer), 'command' (string), 'expected_output' (string), and 'resolution' (string). Schema check: validate step completeness.

error_catalog[].diagnostic_steps[].command

string

Must be a valid, runnable shell command. Test method: execute in a sandbox against the target CLI version; fail if the command returns a non-zero exit code for its own invocation error.

decision_tree_root

object

Must be a valid decision tree node with 'condition' (string), 'true_branch' (object or null), and 'false_branch' (object or null). Null branches are allowed only for leaf nodes. Schema check: no circular references.

PRACTICAL GUARDRAILS

Common Failure Modes

CLI exit code troubleshooting prompts fail in predictable ways. These cards cover the most common failure modes when generating decision-tree guides and how to guard against them before the guide reaches a user.

01

Hallucinated Exit Codes

What to watch: The model invents exit codes that don't exist in the actual CLI source, or assigns wrong numeric values to documented codes. This is especially common for exit codes above 128 or platform-specific signal codes. Guardrail: Provide a ground-truth exit code manifest extracted from source as part of the prompt's [CONTEXT]. Add a post-generation validation step that diffs every code in the output against the manifest and flags any code not present in the source.

02

Diagnostic Steps That Don't Reproduce

What to watch: The generated guide suggests diagnostic commands that fail, produce different output, or require unavailable tools when executed against the actual CLI version. Commands may reference deprecated flags, assume GNU tooling on BSD systems, or depend on environment state the user won't have. Guardrail: Require each diagnostic command in the guide to be executable in a clean test harness. Run every command against the target CLI version and validate exit codes match expectations before publishing the guide.

03

Missing Error Categories

What to watch: The prompt produces a guide covering only the most common exit codes (0, 1, 2) while ignoring less frequent but critical codes like network errors, authentication failures, or resource exhaustion. Users encountering uncovered codes are left without a resolution path. Guardrail: Include a completeness checklist in the prompt's [CONSTRAINTS] that enumerates required error categories: input validation, permissions, network, filesystem, authentication, rate limiting, and internal errors. Validate output coverage against this list.

04

Decision Tree Loops and Dead Ends

What to watch: The troubleshooting decision tree contains cycles where a diagnostic step leads back to an earlier node without progress, or terminates at a leaf node with no resolution action. Users following the guide get stuck. Guardrail: Parse the generated decision tree as a directed graph and check for cycles and leaf nodes that lack a resolution or escalation action. Add a prompt constraint requiring every leaf to end with either a fix, a workaround, or an explicit escalation instruction.

05

Platform-Specific Assumptions Leaking Through

What to watch: The guide assumes Linux paths, bash syntax, or systemd commands when the CLI also runs on macOS, Windows, or container environments. Users on unsupported platforms hit command-not-found errors during diagnosis. Guardrail: Specify the target platform matrix in the prompt's [INPUT] and require platform-conditional branches in the decision tree. Test each diagnostic path against every declared platform in CI before release.

06

Resolution Steps That Mask Root Causes

What to watch: The guide suggests surface-level fixes like 'retry the command' or 'check your connection' without addressing the underlying configuration, permission, or version mismatch that triggered the exit code. Users experience recurring failures. Guardrail: Require each resolution step to include a verification check that confirms the root cause is addressed, not just the symptom. Add an eval criterion that scores resolution depth: does the fix prevent the same exit code from recurring under the same conditions?

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the CLI Exit Code Troubleshooting Guide Prompt before shipping. Each row defines a quality criterion, a concrete pass standard, a failure signal to watch for, and a test method you can automate or run manually.

CriterionPass StandardFailure SignalTest Method

Exit Code Coverage

Every exit code listed in [CLI_EXIT_CODE_REFERENCE] appears in the guide with a dedicated diagnostic path

One or more documented exit codes are missing from the troubleshooting guide output

Parse output for exit code headers; diff against reference list; flag missing codes

Diagnostic Step Actionability

Each diagnostic step includes a runnable command or an observable check, not just a description

A step contains only prose like 'check the logs' without specifying the exact command or log path

Regex scan for imperative command patterns (e.g., grep, cat, journalctl); flag steps with zero actionable commands

Decision Tree Completeness

Every branch in the decision tree terminates in a resolution, escalation, or next-step action

A branch ends with an open question or no guidance (dead-end node)

Parse the decision tree structure; traverse all paths; flag any leaf node without a resolution or escalation action

Error Pattern to Exit Code Mapping

Each error pattern in [ERROR_PATTERNS] maps to exactly one exit code documented in the reference

An error pattern maps to an exit code not in the reference, or maps to multiple conflicting codes

Extract all pattern-to-code mappings from output; validate each code against [CLI_EXIT_CODE_REFERENCE]; flag mismatches

Resolution Verification

Every resolution step references a command whose expected exit code is 0 when the problem is resolved

A resolution step suggests a command that produces a non-zero exit code even in the resolved state

Execute suggested resolution commands in a clean test environment; check exit codes; flag non-zero results

Stderr Pattern Accuracy

Stderr snippets in the guide match actual error output from the CLI version specified in [CLI_VERSION]

A stderr pattern in the guide does not appear in the actual CLI output for that error condition

Trigger each documented error condition; capture stderr; compare against guide patterns with fuzzy match; flag mismatches

Escalation Criteria Clarity

Every diagnostic path includes explicit conditions for when to stop self-service and escalate to a human or support tier

A path lacks any escalation trigger, implying infinite self-service troubleshooting

Scan each diagnostic path for escalation language (e.g., 'contact support', 'escalate to', 'if this fails'); flag paths with zero escalation markers

Cross-Reference Integrity

All internal references to other sections, commands, or exit codes resolve correctly within the guide

A reference points to a non-existent section or an incorrect exit code number

Extract all cross-references; validate each target exists in the output; flag broken or incorrect references

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a single representative exit code and a known error trigger. Focus on generating a correct decision tree for one path before scaling to the full exit code catalog. Drop the structured output schema initially and review the raw markdown for logical flow.

Watch for

  • Diagnostic steps that reference commands or flags that don't exist in the current CLI version
  • Overly generic advice that doesn't map to the specific exit code
  • Missing terminal states where the guide should tell the user to stop and escalate
Prasad Kumkar

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.