> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bindai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 02.5 results

# Results

Every execution in BindAI returns a result object.

Result objects provide a consistent way to determine whether an operation succeeded, inspect its output, or handle errors.

Instead of returning raw strings or provider-specific responses, BindAI returns structured result types across the framework.

***

# Why Results?

Using result objects provides several advantages:

* consistent API
* predictable error handling
* structured outputs
* provider independence
* easier debugging

Applications can always check the success state before using the output.

***

# AgentResult

The most common result type is `AgentResult`.

Every agent execution returns one.

```python id="e2s8kb" theme={null}
result = agent.chat(
    "Explain BindAI."
)
```

Example:

```python id="r7fm5d" theme={null}
print(result.success)

print(result.output)
```

***

# AgentResult Structure

```python id="n4kq8v" theme={null}
AgentResult(
    success=True,
    output="BindAI is an AI framework.",
    error=None,
)
```

Fields:

| Field   | Description                                        |
| ------- | -------------------------------------------------- |
| success | Indicates whether execution completed successfully |
| output  | The final response produced by the agent           |
| error   | Error information when execution fails             |

***

# Checking Success

Always verify that execution completed successfully.

```python id="j5cm2a" theme={null}
result = agent.chat(
    "Hello"
)

if result.success:
    print(result.output)
else:
    print(result.error)
```

This avoids application crashes caused by failed executions.

***

# Handling Errors

When an execution fails:

```python id="m9tw6x" theme={null}
AgentResult(
    success=False,
    output=None,
    error="Provider timeout"
)
```

Applications can inspect the error without relying on exceptions from individual providers.

***

# Structured Output

If an output model is supplied, the result contains the parsed object.

```python id="p8lv3r" theme={null}
result = agent.chat(
    "Create a user profile.",
    output=UserProfile,
)
```

Example:

```python id="y6rn1b" theme={null}
profile = result.output

print(profile.name)
```

Instead of raw text, `output` contains an instance of the requested model.

***

# Workflow Results

Workflow execution also returns a result object.

Example:

```python id="u3ez8h" theme={null}
result = workflow.execute()
```

The output typically contains the workflow variables collected during execution.

```python id="w4ph9m" theme={null}
print(result.output)
```

Example output:

```python id="h8st2c" theme={null}
{
    "summary": "...",
    "approved": True,
}
```

***

# Tool Results

Tools also return structured results.

Example:

```python id="a2nf7v" theme={null}
ToolResult(
    success=True,
    output="Search completed.",
    error=None,
)
```

This allows workflows and agents to process tool responses consistently.

***

# Human Task Results

Human approval nodes store their completion result inside the workflow context.

Example:

```python id="b7lw4s" theme={null}
task.result = {
    "approved": True
}
```

The workflow can use this information after resuming execution.

***

# Success Pattern

Most BindAI result objects follow the same structure.

```text id="v9qx7n" theme={null}
Success

↓

Output

↓

Error
```

This consistency makes it easy to compose agents, tools, and workflows together.

***

# Exceptions vs Results

BindAI prefers returning result objects for expected execution outcomes.

Exceptions are generally reserved for unexpected failures such as:

* programming errors
* invalid configuration
* missing dependencies

Operational failures are represented through result objects whenever possible.

***

# Debugging

Result objects are useful during development.

Example:

```python id="q1dx6p" theme={null}
print(result.success)

print(result.output)

print(result.error)
```

This provides immediate visibility into execution without inspecting provider responses.

***

# Best Practices

* Always check `success` before using `output`.
* Display `error` messages to assist debugging.
* Use structured outputs whenever possible.
* Return consistent result objects from custom tools.
* Avoid returning raw provider responses directly to application code.

***

# Summary

Result objects provide a unified interface for execution outcomes throughout BindAI.

Whether working with agents, tools, or workflows, developers interact with the same predictable success/error model, making applications easier to build, test, and maintain.
