Skip to main content
Handle user input safely with the Agent’s start() and chat() methods, plus optional guardrails for validation.

Quick Start

1

Basic Input with start()

2

Programmatic Input with chat()

3

CLI Input Loop

Input Methods

MethodUse CaseOutput
agent.start(prompt)Interactive terminal useVerbose with streaming
agent.chat(prompt)Scripts, APIs, productionSilent, returns string
agent.run(prompt)Background processingSilent, returns string

Guardrails

Use the guardrails parameter to validate agent outputs before returning:

Function-based Guardrail

LLM-based Guardrail

Guardrail Configuration Options

OptionTypeDescription
validatorCallableFunction: (output) -> (bool, result)
llm_validatorstrLLM prompt for validation
max_retriesintMax retry attempts (default: 3)
on_failstrAction on failure: "retry", "error", "return"

Structured Output Validation

Use Pydantic models to validate and structure agent outputs via the chat() method:

Input Sanitization

Sanitize user input before processing:

Advanced Topics

Prevent abuse with rate limiting:
Securely handle API keys:

Best Practices

Validate All Input

Never trust user input - validate type, format, and content

Use Guardrails

Add guardrails= for output validation and safety

Sanitize for Context

Different contexts need different sanitization (HTML, SQL, shell)

Rate Limit

Prevent abuse with request limits per user

API Reference

Agent Input Methods

MethodDescriptionUse Case
start(prompt)Interactive with verbose outputTerminal, debugging
chat(prompt)Silent, returns stringAPIs, scripts
run(prompt)Silent, production modeBackground jobs

Guardrails Parameter

ValueDescription
CallableFunction: (output) -> (bool, result)
GuardrailConfigFull configuration with retries
strPreset name (e.g., "strict")

Guardrails

Detailed guardrail configuration

Structured Output

Pydantic output validation

Tools

Tool input handling

Agents

Agent configuration