LangExtract
Set up LangExtract with Ollama and expose it as a local API for PDI.
This setup gives you a local LangExtract API backed by Ollama.
At the end, you will have:
LangExtract installed in a Python virtual environment
A FastAPI service running on port
8765A test request that returns structured extractions
A local endpoint ready for use from PDI
These commands assume macOS or Linux.
Use equivalent paths and activation commands on Windows.
Architecture
PDI → HTTP Client → LangExtract API → Ollama model → JSON response
Prerequisites
Pentaho Data Integration
9.x
Community or EE. Spoon and Pan available.
Python
3.10+
Requires pip and venv.
LangExtract
Current GitHub source
Installed from google/langextract.
FastAPI
Current
REST wrapper for LangExtract.
Uvicorn
Current
ASGI server for the API.
Ollama
0.3+
Local LLM runtime.
Ollama Python package
Current
Required by the sample service code.
Model
llama3.1:8b
Pulled locally with Ollama.
PostgreSQL
Optional
Use only if you plan to persist extracted records.
Create project directory
Windows (PowerShell)
Unix
Create and activate virtual environment
Windows
Unix
Install dependencies
Identical on both platforms:
Pull the Ollama model
Identical on both platforms:
Start Ollama
Identical on both platforms:
Leave this running in a separate terminal, or configure it as a service (see step 8).
Start the LangExtract service
Windows
Unix
Run as a background service
Windows - NSSM
Unix - systemd
Create /etc/systemd/system/langextract.service:
Then enable and start:
bash
Open firewall
Windows
Unix (ufw)
Unix (firewalld / RHEL)
Verify
Identical on both platforms:
Response:
Swagger UI (browser): http://localhost:8765/docs
Verify with a test request
Windows
Run a test extraction:
Response:
Unix
Run a test extraction:
Response:
Success means the API returns an extractions array with extracted values and character offsets.
Call the API from PDI
Use the HTTP Client step:
URL:
http://localhost:8765/extractMethod:
POSTContent-Type:
application/jsonRequest body field: your JSON payload
Response field:
response_json
Then parse the response with JSON Input:
Source is from a field:
response_jsonPath:
$.extractions[*]Fields:
class,text,start,end
You can now chain the response into steps such as Select Values, Row Normaliser, or Table Output.
PostgreSQL
Troubleshooting
Common issues:
ModuleNotFoundError: ollamaInstall the Python package withpip install ollama.Connection refused on port
8765Confirm that Uvicorn is running.Empty or weak extractions Improve the prompt and few-shot examples.
Model not found Run
ollama pull llama3.1:8bagain.
Last updated
Was this helpful?
