ContextGem
A free, open-source Python framework extracts document data with local Ollama or LM Studio models and cloud LLMs, linking results to source passages.

ContextGem is a Python framework for developers extracting structured information from documents such as contracts, invoices and reports. You describe what you need in natural language, and it handles extraction prompts and data modelling for text and image content.
- Structured extraction: Pull out entities, dates, JSON objects, classifications, ratings and assessments from whole documents or selected sections.
- Source references: Link extracted values to specific paragraphs and sentences, with justifications that help reviewers check results against the original text.
- Nested analysis: Organize extraction around clauses, chapters, topics and their subsections, then reuse the same requirements across multiple files.
- Model routing: Assign different extraction tasks to different models and use fallback models when needed.
- Saved results: Store processed documents and extraction results for later use without repeating model calls, and save pipelines for reuse.
ContextGem is free and open source under Apache 2.0. Through LiteLLM, it works with local backends including Ollama and LM Studio, plus cloud providers such as OpenAI, Anthropic and Google. Local inference runs on your hardware; cloud extraction sends requests to the chosen provider.
It focuses on individual documents and doesn't support cross-document queries or corpus-wide retrieval. Smaller models can struggle with its detailed extraction instructions; the project recommends models with performance at least comparable to gpt-4o-mini.