Document extraction that makes LLMs cite their sources
ContextGem handles the prompt engineering and source-mapping drudgery of LLM document extraction, letting you declare what you want in plain English.

What it does
ContextGem is a Python framework for extracting structured data and insights from documents using LLMs. You define Aspects (topics, sections, themes) and Concepts (entities, facts, classifications, dates, or anomalies) in natural language, attach them to a Document, and the framework generates prompts, runs extraction, and returns results mapped to specific paragraphs and sentences. It also produces automatic justifications and supports hierarchical pipelines where aspects can contain nested concepts.
The interesting bit
The framework treats source provenance as a first-class feature, not an afterthought. Every extracted item can carry references back to the exact sentences or paragraphs it came from, which is the kind of thing that usually requires post-processing glue after a raw LLM call. The README also notes it was “2nd Product of the week,” suggesting it found an audience tired of hand-rolling extraction pipelines.
Key highlights
- Declarative extraction via
AspectandConceptobjects (includingStringConcept,BooleanConcept,JsonObjectConcept, etc.) - Automatic paragraph- and sentence-level source references with optional justifications
- Hierarchical and multi-level pipelines: aspects can nest concepts, and aspects can be hierarchical
- Reusable extraction pipelines for consistent processing across multiple documents
- Supports both text and image content extraction
Caveats
- The quickstart centers on cloud LLM providers (OpenAI with an API key); broader provider support or local-model compatibility is not detailed in the provided sources.
- You are committing to a specific object model (
Document,Aspect,Concept), which pays off for standard extractions but may fight you if your workflow is highly custom.
Verdict
Good fit for developers building contract analysis, compliance scanning, or report-parsing tools who want structured outputs with citations without maintaining a prompt zoo. Less useful if you need fine-grained control over every token or prompt.
Frequently asked
- What is shcherbak-ai/contextgem?
- ContextGem handles the prompt engineering and source-mapping drudgery of LLM document extraction, letting you declare what you want in plain English.
- Is contextgem open source?
- Yes — shcherbak-ai/contextgem is open source, released under the Apache-2.0 license.
- What language is contextgem written in?
- shcherbak-ai/contextgem is primarily written in Python.
- How popular is contextgem?
- shcherbak-ai/contextgem has 1.9k stars on GitHub.
- Where can I find contextgem?
- shcherbak-ai/contextgem is on GitHub at https://github.com/shcherbak-ai/contextgem.