Add-on: LangChain LLM
Use this skill when an existing project needs LangChain primitives for chat, retrieval, or summarization.
Compatibility
- Works with
architect-python-uv-fastapi-sqlalchemy,architect-python-uv-batch, andarchitect-nextjs-bun-app. - Can be combined with
addon-rag-ingestion-pipeline. - Can be combined with
addon-langgraph-agentwhen graph orchestration is required. - Can be combined with
addon-llm-judge-evals; when used together, declarelangchaininconfig/skill_manifest.jsonso the judge runner can resolve the backend without guessing.
Inputs
Collect:
LLM_PROVIDER:openai|anthropic|ollama.DEFAULT_MODEL: provider model id.ENABLE_STREAMING:yes|no(defaultyes).USE_RAG:yes|no.MAX_INPUT_TOKENS: default8000.
Integration Workflow
- Add dependencies:
- Python:
uv add langchain langchain-core langchain-community pydantic-settings tiktoken
- Next.js:
# Use the project's package manager (examples):
bun add langchain zod
pnpm add langchain zod
- Provider packages (as needed):
uv add langchain-openai langchain-anthropic langchain-ollama
# Use the project's package manager (examples):
bun add @langchain/openai @langchain/anthropic @langchain/ollama
pnpm add @langchain/openai @langchain/anthropic @langchain/ollama
- Add files by architecture:
- Python API:
src/{{MODULE_NAME}}/llm/provider.py
src/{{MODULE_NAME}}/llm/chains.py
src/{{MODULE_NAME}}/api/routes/llm.py
- Next.js:
src/lib/llm/langchain.ts
src/lib/llm/chains.ts
src/app/api/llm/chat/route.ts
- Enforce typed request/response contracts:
- Validate input lengths before chain invocation.
- Return stable schema for streaming and non-streaming modes.
- If
USE_RAG=yes, compose retriever + prompt + model chain:
- Keep retrieval source metadata in outputs.
- Bound document count and token budget.
- If
addon-llm-judge-evalsis also selected:
- emit
config/skill_manifest.jsonwithaddon-langchain-llminaddons - declare
"judge_backends": ["langchain"]incapabilities - allow the judge runner to reuse
DEFAULT_MODELwhenJUDGE_MODELis unset
Required Template
Chat response shape
{
"outputText": "string",
"model": "string",
"provider": "string"
}
Guardrails
-
Documentation contract for generated code:
- Python: write module docstrings and docstrings for public classes, methods, and functions.
- Next.js/TypeScript: write JSDoc for exported components, hooks, utilities, and route handlers.
- Add concise rationale comments only for non-obvious logic, invariants, or safety constraints.
- Apply this contract even when using template snippets below; expand templates as needed.
-
Enforce provider/model allow-lists.
-
Add timeout and retry limits around provider calls.
-
Never log secrets or raw auth headers.
-
On streaming disconnect, stop upstream generation promptly.
-
If judge evals are enabled, keep the judge path on the same provider abstraction instead of bypassing it with ad hoc SDK calls.
Validation Checklist
- Confirm generated code includes required docstrings/JSDoc and rationale comments for non-obvious logic.
uv run ruff check . || true
uv run mypy src || true
# Use the project's package manager (examples):
bun run lint || true
pnpm run lint || true
rg -n "langchain|outputText|provider" src
- Manual checks:
- Typed chat route returns valid response.
- Invalid payloads fail with controlled validation errors.
Decision Justification Rule
- Every non-trivial decision must include a concrete justification.
- Capture the alternatives considered and why they were rejected.
- State tradeoffs and residual risks for the chosen option.
- If justification is missing, treat the task as incomplete and surface it as a blocker.