Skip to main content
Glama

Branch Reachability

branch_reachability
Read-onlyIdempotent

Analyze Python3 function source to determine which branches and loops are reachable, dead, or unknown, with witness inputs, using z3 without executing the code.

Instructions

Which if/elif/else arms and while/for loops of this python3 function can ever run, which are dead code, and what inputs reach each — decided with z3, without running the program.

Use trace_execution instead to see what happened on one run. Use z3_check, not this, when you already have an SMT-LIB2 script to solve directly rather than Python source to translate.

Unannotated parameters default to int. Each branch reports verdict (reachable/dead/unknown), a witness when reachable, and boundary_inputs (min/max/equality-edge for each comparison in its own guard) — every input dict is shaped to drop straight into compare_edge_cases's test_inputs. Refuses, naming the construct and line, prior to any z3 call: floats, attribute access, comprehensions, try/except, imports, data-dependent loop bounds, and anything else outside + - * // %, and/or/not, == != < <= > >=, and abs/min/max/len on int/bool/str. A for loop of at most 32 iterations is unrolled exactly; a longer for, or a while, is checked one iteration at a time — a branch can still come back reachable there, but never dead, and anything past the loop that depends on what it computed comes back unknown rather than a guess.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesPython3 function source to analyze for reachable/dead branches
inputsNoParameter name -> 'int'/'bool'/'str', to narrow or override an unannotated parameter's inferred type
timeoutNoWall-clock seconds before the z3 solver call is abandoned
languageYesSource language of `code`; only python3 functions are analyzed
max_branchesNoMax branches to analyze before stopping; default 64

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed5 schema fields changedv0.12.0
    • addedInput schema / properties / code / description
      Added value: +"Python3 function source to analyze for reachable/dead branches"
    • addedInput schema / properties / inputs / description
      Added value: +"Parameter name -> 'int'/'bool'/'str', to narrow or override an unannotated parameter's inferred type"
    • addedInput schema / properties / language / description
      Added value: +"Source language of `code`; only python3 functions are analyzed"
    • addedInput schema / properties / max_branches / description
      Added value: +"Max branches to analyze before stopping; default 64"
    • addedInput schema / properties / timeout / description
      Added value: +"Wall-clock seconds before the z3 solver call is abandoned"
  2. Addedv0.11.0

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond the readOnly/idempotent annotations, the description discloses substantial non-obvious behavior: it never runs the program, refuses unsupported constructs before any z3 call, unrolls short for-loops exactly, treats long for-loops and while-loops one iteration at a time, and returns unknown rather than guessing for dependent code after such loops. This is far more than the annotations alone provide, and nothing contradicts them.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Although long, the description is densely informative with no filler. It front-loads purpose, then alternatives, then output shape, then limitations, and every sentence carries operational weight needed to invoke the tool correctly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of the tool and the presence of an output schema, the description is complete: it explains the analysis mode, the refusal behavior, loop-handling semantics, output fields, and how outputs connect to compare_edge_cases. An agent has enough context to choose, call, and interpret this tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already covers all five parameters with clear descriptions, giving a baseline of 3. The description adds meaningful parameter-related behavior by stating that unannotated parameters default to int and by enumerating exactly which Python constructs the code parameter accepts or refuses, which directly affects how to supply both code and inputs.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a precise verb and object: it identifies which if/elif/else arms and loops of a Python3 function can run, which are dead code, and what inputs reach each branch, using z3 without executing the program. It also distinguishes itself from sibling tools by naming trace_execution and z3_check as alternatives, so an agent can select it correctly.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives explicit when-to-use and when-not-to-use guidance: use trace_execution for observing a single run, and use z3_check when the input is already an SMT-LIB2 script rather than Python source. It also documents the unsupported-construct boundary, so the agent knows in advance when this tool will refuse.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.