Skip to main content
Glama

backtracking

Generate structured prompts to rewind from failed steps, explore alternatives, and propose corrected plans for error recovery in reasoning tasks.

Instructions

Produce a recursive backtracking scaffold for error correction.

    Args:
        objective: Overall goal to satisfy.
        failed_step: The step or subgoal that failed.
        trace: Optional reasoning trace leading to the failure.
        constraints: Guardrails or requirements to respect.

    Returns:
        Structured prompt that rewinds to last stable state, explores
        alternatives, and proposes a patched plan.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
objectiveYes
failed_stepYes
traceNo
constraintsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The @mcp.tool()-decorated backtracking function that generates a structured prompt for error correction using backtracking.
        @mcp.tool()
        def backtracking(
            objective: str,
            failed_step: str,
            trace: Optional[str] = None,
            constraints: Optional[str] = None,
        ) -> str:
            """Produce a recursive backtracking scaffold for error correction.
    
            Args:
                objective: Overall goal to satisfy.
                failed_step: The step or subgoal that failed.
                trace: Optional reasoning trace leading to the failure.
                constraints: Guardrails or requirements to respect.
    
            Returns:
                Structured prompt that rewinds to last stable state, explores
                alternatives, and proposes a patched plan.
            """
            try:
                model = BacktrackingInput(
                    objective=objective,
                    failed_step=failed_step,
                    trace=trace,
                    constraints=constraints,
                )
            except ValidationError as e:
                return f"Input Validation Error: {e}"
    
            normalized_trace = model.trace or "<none>"
            normalized_constraints = model.constraints or "<none>"
    
            template = """
    /reasoning.backtracking{{
        intent="Recover from failure by stepping back, exploring alternatives, and re-planning",
        input={{
            objective="{objective}",
            failed_step="{failed_step}",
            trace="{trace}",
            constraints="{constraints}"
        }},
        process=[
            /locate_break{{action="Identify point of failure and prior valid state"}},
            /hypothesize{{action="List alternative branches with pros/cons"}},
            /test_branch{{action="Mentally simulate top alternatives against constraints"}},
            /select{{action="Choose next branch with rationale"}},
            /plan_forward{{action="Lay out next steps with checkpoints"}}
        ],
        output={{
            recovery_plan="Steps to proceed from stable state",
            branch_rationale="Why this branch was chosen",
            risks="Remaining risks or unknowns",
            checkpoints="Where to re-verify along the way"
        }}
    }}
    """
            return template.format(
                objective=model.objective,
                failed_step=model.failed_step,
                trace=normalized_trace,
                constraints=normalized_constraints,
            )
  • Pydantic model defining the input schema for the backtracking tool, used for validation.
    class BacktrackingInput(BaseModel):
        objective: str = Field(..., min_length=3, description="Overall goal to satisfy.")
        failed_step: str = Field(
            ..., min_length=3, description="The step or subgoal that failed."
        )
        trace: Optional[str] = Field(
            None, description="Optional reasoning trace leading to the failure."
        )
        constraints: Optional[str] = Field(None, description="Guardrails or requirements.")
  • Invocation of register_thinking_models on the main FastMCP instance, which registers the backtracking tool among others.
    register_thinking_models(mcp)
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the tool 'produces' a scaffold and describes the return value, but it doesn't disclose behavioral traits such as whether it's read-only, destructive, requires specific permissions, or has rate limits. The description is functional but lacks operational context.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded with the purpose in the first sentence. The parameter explanations are concise and directly relevant, though the return value description could be slightly more streamlined. Overall, it avoids unnecessary details.

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

Completeness4/5

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

Given the complexity (error correction tool with 4 parameters), no annotations, and an output schema present, the description is fairly complete. It covers purpose, parameters, and return value, but could benefit from more behavioral context (e.g., safety or performance considerations) to fully compensate for the lack of annotations.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate. It provides detailed semantics for all 4 parameters (e.g., 'objective: Overall goal to satisfy', 'failed_step: The step or subgoal that failed'), adding clear meaning beyond the schema's basic titles and types. This fully addresses the coverage gap.

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 clearly states the tool's purpose: 'Produce a recursive backtracking scaffold for error correction.' It specifies the verb ('produce') and resource ('scaffold'), and distinguishes it from siblings like 'analyze_task_complexity' or 'verify_logic' by focusing on error correction through backtracking rather than analysis or verification.

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

Usage Guidelines3/5

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

The description implies usage when there's a failure ('error correction', 'failed_step'), but it doesn't explicitly state when to use this tool versus alternatives like 'symbolic_abstract' or 'verify_logic'. It provides context (e.g., for handling failures) but lacks explicit exclusions or named alternatives.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/4rgon4ut/sutra'

If you have feedback or need assistance with the MCP directory API, please join our Discord server