Sub topic 12
API churn and dependency weight
This chapter assumes you can write a provider SDK call, validate output with Pydantic, and read a pip dependency list. It covers two costs of frameworks that show up after the first demo works: the API changes under you, and the install grows.
What API churn looks like
LLM frameworks and provider SDKs are young and change fast. Three kinds of change cause most breakage:
- Renamed or moved imports. Code that imported from one package path stops working after the project splits into several packages.
- Replaced interfaces. An older way of building chains or agents is deprecated in favor of a newer one, and tutorials written for the old way stop working.
- Renamed fields. The PydanticAI example earlier in this tutorial uses
output_typeandresult.output. Earlier releases used different names, so the same code fails on an older or newer install.
Provider SDKs change too. The OpenAI-style chat.completions.create call is stable and widely copied. That is a practical advantage, because other providers offer compatible endpoints. A framework wraps that call in its own layer, and you inherit the framework's change rate on top of the provider's.
Dependency weight
Every framework you install brings its own dependencies. A direct SDK project may need two or three packages. A framework project often needs dozens, including provider integrations, HTTP clients, and parsing libraries.
Heavier dependencies cause concrete problems:
- Longer installs and larger container images.
- More chances of version conflicts with other libraries in your environment.
- A bigger surface for security advisories that you must track.
- Slower cold starts in serverless setups.
You can measure this yourself. Create two clean virtual environments, install one approach in each, and compare the results:
import subprocess
import sys
result = subprocess.run(
[sys.executable, "-m", "pip", "list", "--format=freeze"],
capture_output=True,
text=True,
check=True,
)
packages = result.stdout.strip().splitlines()
print(f"{len(packages)} packages installed")Run this script once in an environment containing only openai and pydantic, and once in one containing your framework of choice. The counts differ, and the difference is what you must maintain.
Reducing the risk
You can't remove churn, but you can limit how far it spreads.
- Pin versions. Lock exact versions in a requirements file or lock file so an install next month matches today's.
- Read release notes before upgrading. Upgrade deliberately, not as a side effect of rebuilding an image.
- Isolate the framework. Put framework calls behind one small module of your own. The rest of the code calls your function, not the framework.
- Install only what you use. Many frameworks split integrations into separate packages. Add the ones you need, not the umbrella package.
- Keep a test that calls your wrapper. A small test with a stubbed model makes an upgrade failure visible immediately.
The isolation step looks like this:
# llm.py: the only file that imports a model library
from openai import OpenAI
_client = OpenAI()
def ask(question: str) -> str:
response = _client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": question}],
)
return response.choices[0].message.contentIf you later switch to LangChain or back, you rewrite llm.py and leave callers alone. The next chapters on decision criteria and migration build on this boundary.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `ImportError` after a rebuild | Unpinned upgrade moved a module | Pin versions, then adjust the import |
| `AttributeError` on a result field | Field renamed between releases | Check the release notes for your installed version |
| Tutorial code fails on a fresh install | Tutorial targeted an older release | Match the tutorial's version or update the code |
| Install conflicts with another library | Overlapping dependency ranges | Use a separate environment for the project |
Exercise
Your service builds correctly on Monday and fails on Tuesday with an AttributeError, and you changed no code. What is the most likely cause, and which two practices would have prevented it?
Show answer
An unpinned dependency was upgraded during the Tuesday build, and a field or method was renamed in the new release. Pinning exact versions and upgrading deliberately after reading the release notes would have prevented it. Isolating framework calls in one wrapper module would also have limited the damage to one file.