Sub topic 13
Choosing an approach for your project
This chapter assumes you can write basic Python, have called a chat API before, and have seen the SDK, structured output, tool calling, and retrieval examples from earlier chapters. Here you will turn those comparisons into a decision.
Start from the task, not the tool
Most projects need one or two capabilities from this list: a single model call, validated output, tool calling, a multi-step agent, or retrieval over your documents. Name those first. Then ask which approach covers them with the least code you don't understand.
Criteria that matter
| Criterion | Provider SDK | LangChain | LlamaIndex | PydanticAI |
|---|---|---|---|---|
| Control over the request | Full | Partial, through wrappers | Partial | Good, with typed layers |
| Provider portability | Low | High | Medium to high | High |
| Retrieval from documents | Write it yourself | Components available | Strongest fit | Not a focus |
| Typed, validated output | Manual with Pydantic | Supported | Supported | Core design |
| Debuggability | Easiest | Needs tracing tools | Needs tracing tools | Moderate |
| Exposure to API churn | Provider changes only | High | Medium to high | Moderate, and the library is young |
Treat the table as a starting point. Check the current release notes of any library before you commit to it.
A decision path
Working through three cases
A support-ticket classifier. One call per ticket, a fixed schema, no retrieval. The manual JSON-mode and Pydantic pattern from earlier covers this in about twenty lines. A framework adds a dependency and gains almost nothing.
A question-answering tool over 2,000 internal documents. You need loading, chunking, embedding, indexing, and querying. You could write each stage by hand, but LlamaIndex removes the most code here. Start with its defaults, then replace the parts you need to tune.
An assistant that must run on two different providers. Portability is the requirement, so a common model interface earns its cost. LangChain and PydanticAI both provide one. PydanticAI suits you better if typed output matters most. LangChain suits you better if you also need its many integrations.
Common errors in choosing
- Picking a framework for the tutorial's sake. A demo that is short in a framework is not evidence that your production system will be.
- Ignoring the cost of debugging. When a bad answer appears, you must see the exact messages sent. A framework with no tracing in place makes that hard.
- Over-weighting portability. Providers differ in features such as tool-call formats and structured-output support. A common interface hides those differences until the day they matter.
- Rewriting too early. Moving to a framework because the SDK code feels long is premature if the code is still easy to read.
Mixing is allowed
The choices are not exclusive. A common arrangement uses LlamaIndex for retrieval, a thin SDK call for generation, and Pydantic for validation. Keep the boundaries clear: pass plain strings and Pydantic objects between parts, not framework-specific types. That keeps each piece replaceable, which the next chapter builds on.
Exercise
A team needs to extract an invoice number and total from emails, one model call per email, with a fixed schema. They are considering LangChain "to be safe for the future." What would you recommend, and why?
Show answer
Use the provider SDK with JSON mode and Pydantic validation. The task is one call with a fixed schema, so a framework adds dependency weight and API churn without removing meaningful code. Plain Pydantic types also make a later move to a framework easy if the needs grow, for example to several providers or retrieval.
Exercise
Your project searches 5,000 PDFs and answers questions from them, and you expect to tune chunk size and retrieval settings. Which approach from this chapter is the best starting point, and what is one risk?
Show answer
LlamaIndex, because it is built around ingestion, indexing, and querying. One risk is that its defaults hide details, such as which models are used and what prompt is sent, so you should add tracing to see the actual requests.