Inferensys

Prompt

Untested Code Path Identification Prompt

A practical prompt playbook for using Untested Code Path Identification Prompt in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Understand the ideal workflow, required inputs, and boundaries for the untested code path identification prompt before integrating it into your CI pipeline.

This prompt is designed for developers and QA engineers who need to analyze a single source file or module to find conditional branches, exception handlers, and loop boundaries that lack corresponding test cases. It is meant to be run before merging code, as part of a pre-commit or CI pipeline analysis step. The core job-to-be-done is producing a prioritized list of uncovered code paths with specific, actionable input suggestions that would trigger each path. This is not a replacement for a full coverage tool or a human code review. It is a focused analysis layer that reasons about reachability and test gaps at the path level, which line-coverage tools often miss because they can't distinguish between a covered line with untested branches and a truly exercised path.

To use this prompt effectively, you must provide the full source code of a single file or module as the [INPUT], along with any existing test file contents as [CONTEXT]. The model needs to see both the implementation and the tests to identify gaps. The ideal user is a developer who has just finished a feature or bug fix and wants to ensure they haven't introduced untested logic paths. The prompt works best on files with clear conditional logic—functions with if/else chains, try/catch blocks, loops with break conditions, and switch statements. It is less useful for purely declarative code, configuration files, or simple getter/setter methods where path coverage is trivial. Do not use this prompt on generated code, minified files, or code you don't have permission to analyze.

This prompt should not be used as a sole gate for merge decisions. It identifies potential gaps but cannot verify whether existing tests actually assert the correct behavior on those paths—it only checks for the presence of test coverage. Always pair the output with human judgment, especially for security-critical paths, authentication logic, and data integrity operations. The prompt also assumes that the provided test code is the complete test suite for that module; if tests are split across multiple files, you must aggregate them before running the analysis. For high-risk domains like financial transactions or healthcare data processing, require a second reviewer to validate each flagged gap before closing the issue. After running this prompt, take the prioritized list of uncovered paths and feed the highest-risk items into your test case generation workflow or manual test planning session.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Untested Code Path Identification Prompt delivers value and where it introduces risk. Use these cards to decide if this prompt fits your current workflow.

01

Good Fit: Pre-Merge Code Review

Use when: A developer submits a pull request and you need to automatically flag new conditional branches, exception handlers, or loop boundaries that lack corresponding test cases before the code reaches QA. Guardrail: Integrate the prompt into your CI pipeline with a blocking threshold for high-risk, uncovered paths. Always require a human to confirm the finding is reachable before failing the build.

02

Good Fit: Legacy Module Hardening

Use when: You inherit a legacy module with low test coverage and need a systematic map of every untested code path to prioritize remediation. Guardrail: Run the prompt on one file at a time. Pair the output with a dynamic coverage tool to validate that the suggested inputs actually trigger the identified paths before adding tests to the suite.

03

Bad Fit: Dynamic or Metaprogrammed Code

Avoid when: The codebase relies heavily on runtime metaprogramming, dynamic dispatch, or eval-style execution where control flow is not statically analyzable from the source text. Guardrail: The prompt cannot reason about paths constructed at runtime. Use dynamic analysis and tracing tools for these modules instead of a static prompt-based approach.

04

Bad Fit: High-Level Architectural Review

Avoid when: You need to assess integration test gaps across multiple services, databases, and message queues. This prompt operates on a single file or module. Guardrail: For cross-service gaps, use a dedicated End-to-End Test Gap Analysis Prompt that traces user journeys through the full call chain, not this single-module tool.

05

Required Inputs

What you must provide: The full source code of the target file or module, and a report or listing of the existing test suite covering that file. Without the test suite context, the model cannot distinguish between covered and uncovered paths. Guardrail: If you cannot provide a reliable test coverage mapping, use a code coverage tool to generate one before invoking this prompt.

06

Operational Risk: False Positives in Dead Code

What to watch: The prompt may flag unreachable code paths, defensive branches that are impossible to trigger in practice, or paths already covered by integration tests outside the provided test suite. Guardrail: Every flagged path must be manually verified for reachability. Add a validation step in your harness that attempts to execute the suggested input against the actual code before accepting the finding as a genuine gap.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt that identifies untested conditional branches, exception handlers, and loop boundaries in source code and returns a structured JSON array of uncovered paths with trigger inputs.

The prompt below is designed to be dropped into your AI harness, CI pipeline, or local evaluation runner. It expects source code and a list of existing tests as input, then systematically identifies code paths that lack coverage. The output is a JSON array, making it straightforward to parse, validate, and feed into downstream test generation tools or ticketing systems.

text
You are a test coverage analyst. Analyze the provided source code against the list of existing tests.

Identify every conditional branch, exception handler, and loop boundary that is not exercised by any existing test. For each uncovered path, provide a concrete input that would trigger it.

Return the results as a JSON array of objects with the following structure:
[
  {
    "file": "string (file path or module name)",
    "line_range": "string (e.g., '42-48')",
    "construct_type": "string (one of: conditional_branch, exception_handler, loop_boundary)",
    "uncovered_path_description": "string (what specific path is not tested)",
    "trigger_input": "string (concrete input that would exercise this path)",
    "risk_level": "string (one of: high, medium, low)",
    "rationale": "string (why this gap matters)"
  }
]

[SOURCE_CODE]
[EXISTING_TESTS]
[CONSTRAINTS]

Adapt the template by replacing the square-bracket placeholders. [SOURCE_CODE] should contain the full file or module under analysis. [EXISTING_TESTS] should list the test functions, methods, or cases that currently exist, including their names and the paths they cover if known. [CONSTRAINTS] is optional but useful for adding domain-specific rules, such as ignoring deprecated code paths, enforcing a minimum risk threshold for reporting, or limiting analysis to specific function scopes.

Before integrating this prompt into a production pipeline, validate the output against a known codebase with documented coverage gaps. Confirm that each returned object maps to a reachable code path and that the suggested trigger input would genuinely exercise it. For high-risk codebases such as authentication, payment processing, or safety-critical systems, always require human review of the identified gaps before generating remediation tickets. Avoid using this prompt as a standalone coverage gate; combine it with actual coverage tool data and static analysis results for a complete picture.

IMPLEMENTATION TABLE

Prompt Variables

Required and optional inputs for the Untested Code Path Identification Prompt. Each placeholder 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

[SOURCE_CODE]

The complete file or module content to analyze for untested paths

def process_order(status, items): if status == 'pending': ...

Parse check: must be non-empty string. Validate syntax for target language before passing. Null not allowed.

[LANGUAGE]

Programming language of the source code to enable syntax-aware analysis

python

Must match one of the supported language identifiers in the harness config. Enum check: python, javascript, typescript, java, go, rust, csharp. Null not allowed.

[EXISTING_TEST_SUITE]

Current test code or test case descriptions for coverage comparison

def test_process_order_confirmed(): assert process_order('confirmed', []) == []

Parse check: may be empty string if no tests exist. If provided, validate syntax matches [LANGUAGE]. Null allowed if no tests exist.

[COVERAGE_REPORT]

Optional structured coverage data to cross-reference with identified gaps

{"file": "orders.py", "uncovered_lines": [12, 15, 23, 24, 25, 41]}

Schema check: if provided, must contain file path and uncovered_lines array. Format: JSON. Null allowed. If null, prompt relies solely on static analysis of [SOURCE_CODE].

[ANALYSIS_DEPTH]

Controls how exhaustively the prompt searches for untested paths

exhaustive

Enum check: must be one of 'basic' (branches only), 'standard' (branches + exception handlers), 'exhaustive' (branches + exceptions + loop boundaries + edge cases). Default: 'standard'. Null not allowed.

[PRIORITY_WEIGHTS]

Risk-weighting preferences to influence path prioritization

{"security_paths": 10, "data_mutation": 8, "error_handling": 7, "core_logic": 6}

Schema check: must be valid JSON object with numeric weights. Keys must match known risk categories. Null allowed; prompt uses default equal weighting.

[OUTPUT_FORMAT]

Desired structure for the untested path report

json

Enum check: must be 'json', 'markdown', or 'sarif'. Default: 'json'. Null not allowed. If 'sarif', output must conform to SARIF 2.1.0 schema for CI integration.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Untested Code Path Identification Prompt into a CI pipeline, IDE plugin, or manual review workflow with validation, retries, and human review gates.

This prompt is designed to operate on a single file or module at a time, receiving the source code and optionally a coverage report or test file listing as context. The most reliable integration pattern is a pre-merge CI job that triggers when a pull request modifies files in watched directories. The harness should extract the diff, identify changed files, and invoke the prompt once per file with the full file content and the project's existing test manifest. For large files, consider splitting the file into logical sections (functions, classes) and running the prompt per section to avoid context window limits and improve precision. The prompt expects [SOURCE_CODE] and [EXISTING_TESTS] as inputs; the harness is responsible for assembling these from the repository state at the time of the PR.

Validation and output contracts are critical because this prompt produces structured findings that downstream tools consume. The harness must validate that each returned path includes: a reachable code location (file, line range, function name), the condition or branch that creates the untested path, a suggested input to trigger it, and a severity or priority ranking. Reject any finding that lacks a specific line reference or whose suggested input does not match the parameter types or constraints visible in the source. A second validation pass should deduplicate findings that describe the same code path with different phrasing. For high-risk codebases (auth, payments, data integrity), add a human review flag that prevents automatic merge if the prompt identifies CRITICAL severity gaps in security-sensitive modules.

Model choice and retry strategy matter here. Use a model with strong code reasoning capabilities (GPT-4o, Claude 3.5 Sonnet, or equivalent) because the task requires tracing control flow through conditionals, loops, and exception handlers. Set temperature to 0 or very low (0.0–0.1) to maximize deterministic output. If the output fails validation (missing fields, unparseable JSON, unreachable paths), retry once with the same input and a stricter system instruction that emphasizes the required schema. If the second attempt fails, log the failure, attach the raw output to the PR as a comment, and do not block the merge on this prompt alone—instead, surface it as a non-blocking advisory. For teams using tool-calling APIs, define a strict function schema for the output (e.g., list_uncovered_paths with typed fields for location, condition, suggested_input, severity) rather than relying on unstructured text parsing.

Logging and observability should capture: the file path, the prompt version, the model used, the number of findings returned, validation pass/fail status, and any retry attempts. Store these in your prompt observability system so you can correlate untested path findings with actual post-merge incidents over time. This data is essential for calibrating the prompt's severity scoring and reducing false positives. Do not use this prompt as the sole gate for merge decisions; combine its output with actual coverage tool data, static analysis results, and human code review. The prompt identifies likely gaps—it does not execute tests or measure coverage. Treat its output as a prioritized investigation list, not a definitive coverage report.

IMPLEMENTATION TABLE

Expected Output Contract

Define the structure, types, and validation rules for the untested code path report so downstream tooling and review workflows can consume it reliably.

Field or ElementType or FormatRequiredValidation Rule

untested_paths

Array of objects

Must be a non-empty array if gaps are found; empty array only when no untested paths exist

untested_paths[].id

String (kebab-case)

Must match pattern ^UP-[0-9]{3}$ and be unique within the array

untested_paths[].file_path

String (relative path)

Must resolve to a file present in the provided [REPO_CONTEXT] or [DIFF]

untested_paths[].line_range

Object with start and end integers

start <= end; both must be positive integers within the file's line count

untested_paths[].construct_type

Enum: conditional | loop | exception_handler | early_return | switch_case | ternary

Value must match one of the allowed enum members exactly

untested_paths[].reachability_rationale

String

Must be non-empty and reference a specific input condition or state that triggers the path

untested_paths[].suggested_test_input

Object or null

If reachable, must include input_params and expected_behavior; if unreachable, set to null with dead_code set to true

untested_paths[].priority

Enum: critical | high | medium | low

critical reserved for paths in auth, data mutation, or external service calls; low only for logging or cosmetic paths

PRACTICAL GUARDRAILS

Common Failure Modes

When identifying untested code paths, these failures degrade trust and actionability. Each card pairs a specific failure with a concrete guardrail to keep the output useful for QA automation and CI/CD pipelines.

01

Hallucinated Unreachable Paths

What to watch: The model invents conditional branches or exception handlers that do not exist in the source code, creating phantom test gaps. Guardrail: Require the harness to validate every flagged path against the AST or control-flow graph before surfacing it. Reject any gap that cannot be mapped to a specific line range in the diff.

02

Ignored Existing Test Coverage

What to watch: The prompt flags code paths as untested when corresponding test cases already exist, producing redundant recommendations that waste QA effort. Guardrail: Supply the existing test suite or coverage report as input context. Instruct the model to cite the specific test that covers a path or explicitly state why coverage is missing before flagging a gap.

03

Vague Test Input Suggestions

What to watch: The output describes what to test but omits concrete input values, expected outcomes, or the specific code path to exercise, making recommendations untranslatable into test code. Guardrail: Enforce a strict output schema requiring input_values, expected_behavior, and code_path_exercised fields for every gap. Validate schema compliance before accepting the response.

04

Missing Negative and Failure Cases

What to watch: The model identifies happy-path gaps but overlooks exception handlers, error returns, and authorization denial paths that lack test coverage. Guardrail: Explicitly enumerate failure modes in the prompt instructions: error returns, thrown exceptions, null inputs, permission denials, and timeout paths. Require at least one negative test recommendation per error-handling block.

05

Context Window Truncation on Large Files

What to watch: For large source files or modules, the model runs out of context and silently drops analysis of later functions, producing incomplete gap reports. Guardrail: Chunk the file by function or class boundary before analysis. Run the prompt per-chunk and merge results. Add a completeness check that verifies every function in the file appears in the output.

06

Misidentified Risk Priority

What to watch: The model assigns high severity to low-impact gaps (e.g., logging branches) while downplaying untested security or data-integrity paths. Guardrail: Provide a risk rubric in the prompt that weights authorization logic, data mutations, and external calls higher than logging or formatting branches. Require a risk_score with explicit rationale per gap.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to evaluate the quality of the Untested Code Path Identification prompt's output before integrating it into a CI pipeline or QA workflow. Each criterion should be assessed against a representative sample of code files.

CriterionPass StandardFailure SignalTest Method

Path Reachability

Every identified untested path is confirmed reachable via static call graph analysis or manual trace.

Output includes dead code, unreachable branches, or compiler-eliminated blocks flagged as untested.

For each flagged path, trace the control flow from a public entry point. Flag any path that cannot be reached.

Coverage Gap Accuracy

Each flagged gap maps to a specific conditional branch, exception handler, or loop boundary that lacks a corresponding test case in the provided test suite.

Output lists functions or files without pinpointing the specific uncovered branch; or flags paths already covered by existing tests.

Cross-reference each gap against the provided test suite. A gap fails if an existing test exercises that exact branch.

Input Suggestion Validity

Suggested inputs for each gap are concrete, valid, and would trigger the identified code path when executed.

Suggested inputs are generic, syntactically invalid, or would not exercise the target branch due to upstream conditions.

For a sample of gaps, execute the suggested input in a debugger or test harness and verify the target branch is hit.

Priority Ordering Rationale

Gaps are prioritized by a combination of execution likelihood and failure impact, with a clear rationale for the top 3 items.

All gaps are assigned the same priority, or the ordering appears random with no connection to risk or reachability.

Review the top 3 and bottom 3 items. Verify that the rationale for their relative positions is sound and documented.

False Positive Rate

Fewer than 10% of flagged gaps are false positives (paths already tested or unreachable).

More than 20% of flagged gaps are false positives, causing alert fatigue and eroding trust in the tool.

Run the prompt on 5 code files with known coverage. Manually verify each flagged gap and calculate the false positive ratio.

Completeness of Exception Paths

All try-catch blocks and error return paths in the code are analyzed, with untested exception handlers explicitly listed.

Exception handling paths are ignored, or only the 'happy path' is analyzed while catch blocks are omitted.

For a file with known exception handling, verify that every catch block and error return statement appears in either the covered or untested list.

Output Schema Compliance

Output strictly matches the defined [OUTPUT_SCHEMA] with all required fields present and correctly typed.

Output is missing required fields, uses incorrect types, or adds hallucinated fields not in the schema.

Validate the raw output against the [OUTPUT_SCHEMA] using a JSON Schema validator. Reject if validation fails.

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a single file and a lightweight coverage report. Drop strict output schemas and focus on getting a readable list of uncovered paths. Accept plain text or bulleted output instead of structured JSON.

Prompt modification

  • Remove [OUTPUT_SCHEMA] and replace with: List each untested path with the condition and a suggested input to trigger it.
  • Add: If you are unsure whether a path is covered, flag it with CONFIDENCE: LOW and explain why.
  • Keep [SOURCE_CODE] and [TEST_SUITE] as the only required inputs.

Watch for

  • Paths flagged without reachability reasoning
  • Overly broad suggestions that don't map to specific lines
  • Missing distinction between dead code and genuinely uncovered paths
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.