On this page
Gemini
Gemini is the primary provider used in LangExtract examples. With the LangExtract API key configured via
LANGEXTRACT_API_KEY, you can access models like gemini-2.5-flash with strong
performance and low latency.
import langextract as lx
result = lx.extract(
text_or_documents=text,
prompt_description="Extract entities and relationships.",
model_id="gemini-2.5-flash",
)
See Getting started for installation, and the main Docs for guidance on designing extraction prompts and schemas.
Vertex AI
For production workloads that require enterprise security and governance, you can use LangExtract with Vertex AI. This lets you run Gemini models with service accounts, regional endpoints, and custom quotas.
result = lx.extract(
text_or_documents=batch_of_documents,
prompt_description="Summarize and structure key fields.",
model_id="gemini-2.5-flash",
language_model_params={
"vertexai": True,
"project": "your-project-id",
"location": "us-central1",
},
)
Learn more about batch processing and cost‑efficient workflows on the Benchmarks page and in the Examples section.
OpenAI
LangExtract includes optional support for OpenAI models, so you can reuse the same extraction logic with
models like gpt-4o. OpenAI support currently relies on fenced output rather than full
schema constraints.
result = lx.extract(
text_or_documents=text,
prompt_description=prompt,
examples=examples,
model_id="gpt-4o",
api_key=os.environ["OPENAI_API_KEY"],
fence_output=True,
use_schema_constraints=False,
)
If you are interested in stricter schema enforcement, check the GitHub issues and roadmap.
Ollama (local models)
For fully local deployments or experimentation without cloud APIs, LangExtract can call models served by Ollama. This is ideal for environments with strict data residency requirements.
result = lx.extract(
text_or_documents=text,
prompt_description=prompt,
examples=examples,
model_id="gemma2:2b",
model_url="http://localhost:11434",
fence_output=False,
use_schema_constraints=False,
)
The Examples section includes sample scripts that demonstrate local extraction flows alongside cloud‑based ones, so you can compare quality and performance.
Custom providers
LangExtract’s provider system is plugin‑based. You can implement your own provider as a separate Python
package, register it, and use it via model_id without changing core LangExtract code.
Typical use cases for custom providers include:
- Routing requests through an internal gateway or proxy.
- Supporting additional third‑party LLM APIs.
- Wrapping domain‑specific models with custom logging or safety checks.
For inspiration, check the community provider list referenced on the Community page and the provider guidelines linked from the official repository.