> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc-studio-tools-doc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Early Stopping

> How to early stop workflows

Workflows support early termination when specific conditions are met, preventing unnecessary processing and implementing safety gates. Any step can trigger early termination by returning `StepOutput(stop=True)`, immediately halting the entire workflow execution.

<img className="block dark:hidden" src="https://mintcdn.com/phidatainc-studio-tools-doc/deBcuBANRxcagGon/images/workflows-early-stop-light.png?fit=max&auto=format&n=deBcuBANRxcagGon&q=85&s=ff2ae0604e4d7e8e9b7981dfe8efe412" alt="Workflows early stop diagram" width="7281" height="1179" data-path="images/workflows-early-stop-light.png" />

<img className="hidden dark:block" src="https://mintcdn.com/phidatainc-studio-tools-doc/deBcuBANRxcagGon/images/workflows-early-stop.png?fit=max&auto=format&n=deBcuBANRxcagGon&q=85&s=939a207d814d5750deeb73ee852b914f" alt="Workflows early stop diagram" width="7281" height="1179" data-path="images/workflows-early-stop.png" />

## Example

```python theme={null}
from agno.workflow import Step, Workflow, StepInput, StepOutput

def security_gate(step_input: StepInput) -> StepOutput:
    """Security gate that stops deployment if vulnerabilities found"""
    security_result = step_input.previous_step_content or ""
    
    if "VULNERABLE" in security_result.upper():
        return StepOutput(
            content="SECURITY ALERT: Critical vulnerabilities detected. Deployment blocked.",
            stop=True  # Stop the entire workflow
        )
    else:
        return StepOutput(
            content="Security check passed. Proceeding with deployment...",
            stop=False
        )

# Secure deployment pipeline
workflow = Workflow(
    name="Secure Deployment Pipeline",
    steps=[
        Step(name="Security Scan", agent=security_scanner),
        Step(name="Security Gate", executor=security_gate),  # May stop here
        Step(name="Deploy Code", agent=code_deployer),       # Only if secure
        Step(name="Setup Monitoring", agent=monitoring_agent), # Only if deployed
    ]
)

# Test with vulnerable code - workflow stops at security gate
workflow.print_response("Scan this code: exec(input('Enter command: '))")
```

## Developer Resources

* [Early Stop Workflow](/workflows/usage/early-stop-workflow)
