LLMBuilder provides a fluent API for constructing LLM clients that can return Pydantic-validated objects directly, without the overhead of the agent run lifecycle.
Use this pattern for classification, extraction, summarization, and any scenario where you want a single LLM call with a guaranteed output schema.
Example
The builder pattern
LLMBuilder uses a fluent (method-chaining) API to construct an LLM client with the exact configuration you need:
.build() call at the end constructs the final LLMClient with all specified settings.
Available builder methods:
| Method | Purpose |
|---|---|
.provider(name) | Set the LLM provider ("openai", "litellm", "anthropic_agent"). |
.model(name) | Set the model identifier. |
.profile(name) | Apply a named configuration profile ("production", "development", etc.). |
.temperature(value) | Set sampling temperature (0.0-2.0). |
.max_tokens(value) | Set maximum response tokens. |
.top_p(value) | Set nucleus sampling parameter. |
.timeout(seconds) | Set request timeout. |
.build() | Construct and return the LLMClient. |
Structured output with Pydantic
When you passresponse_model=YourModel to client.chat(), the client instructs the LLM to return output that conforms to the model’s JSON schema. The response is parsed and validated against the Pydantic model:
- If the LLM returns valid structured output,
resp.structured_responsecontains the parsed dictionary andresp.textcontains the raw response. - If the LLM returns output that does not match the schema, a
LLMInvalidResponseErroris raised.
response_format parameter) when available, with a fallback to prompt-based JSON extraction.
When to use LLMBuilder vs Runner
| Use Case | Approach |
|---|---|
| Single LLM call, no tools, no memory | LLMBuilder — simpler, faster, no lifecycle overhead. |
| Structured extraction or classification | LLMBuilder with response_model. |
| Multi-turn conversation with tools | Runner — provides the full agent loop with tool execution, policy, and memory. |
| Subagent delegation | Runner — only the runner supports subagent dispatch. |
| Event streaming to a UI | Runner with run_stream(). |
| Eval-driven development | Runner — evals require the full AgentResult lifecycle. |
LLMBuilder when you want precision and control over a single LLM interaction. Use Runner when you need the full agentic lifecycle.