ContextGem

ContextGem

Shcherbak AI · Coding · Other

ContextGem is a free, open-source Python library that handles LLM document extraction, pulling structured data and insights from documents with minimal code.

Interface preview of ContextGem

About ContextGem

What Is ContextGem

ContextGem is a Python library for LLM document extraction. It turns messy documents into structured data. You describe what you want in plain language, and the framework handles the rest: building prompts, validating the output, and mapping every answer back to the paragraph or sentence it came from.

The problem it solves is the gap between raw text and usable fields. Contracts, reports, and policy files hold the numbers, dates, and labels you need, but they arrive as one long block. ContextGem splits that block into meaningful pieces and fills a schema you define, so the result slots into a database or a report without hand-cleaning.

The limits matter as much as the promise. It's built for deep analysis of a single document at a time, and the creators say it does not handle cross-document queries or corpus-wide search. If you need to ask questions across thousands of files, a retrieval framework like LlamaIndex is the better fit. ContextGem also assumes you can write and run Python.

Getting Started

  1. Install the package with uv add contextgem or pip install -U contextgem on Python 3.10 to 3.14.
  2. Create a Document object and pass in your raw text.
  3. Define Aspects for the sections you want, such as clauses or chapters, and Concepts for the specific fields, such as fees or dates.
  4. Connect an LLM through DocumentLLM, using a cloud provider like OpenAI or a local model through Ollama.
  5. Run the extraction and read the results, which come back with references pointing to the source text.

Product Information

A quick look at ContextGem's pricing, supported platforms, and performance.

Free PlanYes
Paid PlansFree
PlatformPython (cross-platform)
DeveloperShcherbak AI
CategoryCoding · Other
Release DateOct 2024
Latest UpdatedDec 2025
Website Visits649.3M
Website Global Rank50
API AvailabilityYes

Best for

The users, tasks, and scenarios where this tool fits best.

Users

  • Python developers
  • Legal and finance teams with scripting help
  • Researchers and analysts

Tasks

  • Contract review
  • Invoice and receipt processing
  • Research summarization
  • Policy and report parsing

Scenarios

  • Building an extraction pipeline once and reusing it across many files
  • Catching the exact sentence behind a number
  • Running extraction on private data offline

Key features

Aspects for Sections, Concepts for Fields

ContextGem splits the job in two. Aspects find whole sections, like termination clauses or payment terms, while Concepts pull the specific data points inside them, such as a monthly fee or a due date. That two-stage design keeps extraction focused: you narrow to the right part of a document before you ask for fine details, which makes results more accurate on long files and keeps the structured data clean.

Seven Concept Types for Structured Output

The library ships with seven concept types: string, boolean, numerical, date, rating, JSON object, and label. Each one maps to a kind of answer, so a rating concept expects a number on a scale and a label concept picks from a list you set. Using typed concepts means the output arrives in the shape you need instead of a block of text you parse by hand.

Source References Down to the Sentence

Every extracted value keeps a link to the source text. Items carry paragraph references by default, and you can switch reference_depth to sentences for finer tracking. When a figure looks wrong during review, you can jump straight to the lines behind it rather than searching the whole document. Justifications are available too, so the model explains why it picked each item.

Declarative, Reusable Pipelines

An LLM extraction pipeline bundles aspects and concepts into one reusable, serializable setup. You define it once, save it, and apply it to new documents with the same structure. Concurrency, retries, and cross-provider usage tracking are built in, so a batch of files runs without you managing the loop yourself. Serialization means a pipeline can move between machines or get stored as a versioned artifact.

Works With Cloud and Local Models

ContextGem routes to any model that LiteLLM supports, covering OpenAI, Anthropic, Google, Azure, and xAI, plus local models through Ollama and LM Studio. That range lets you pick a fast, cheap model for simple pulls and a reasoning model for thorny clauses. Running locally keeps sensitive documents on your own hardware, which matters for legal and medical work.

Justifications and Few-Shot Examples

You can ask the model to explain each extraction, with brief, balanced, or detailed justifications, plus a cap on sentence length. You can also attach examples to calibrate the model on your document type before it runs. Both features target accuracy: the examples teach the pattern, and the justifications let you audit the output instead of trusting it blind.

Pros and cons

Pros

  • Free and open source: this Python library ships under Apache 2.0, so there are no per-document fees and you can read or change the code yourself.
  • Minimal code: describing targets in plain language beats hand-building prompts, which saves setup time on every new document type.
  • Precise source tracking: paragraph and sentence references let you verify any value against the original text, a real help for legal and finance review.
  • Model flexibility: the same setup runs on cloud providers or local models, so you choose between convenience and data control.

Cons

  • Single-document scope: the framework does not do cross-document queries or corpus-wide search, so teams needing a knowledge base across many files have to reach for a retrieval tool instead.
  • Requires Python skills: it is a developer library, not a point-and-click app, so non-coders can't use this open-source document parser without help, and there is no hosted version to fall back on.
  • Local models need setup: free offline use sounds appealing, but running Ollama or LM Studio and picking a capable model takes its own effort and hardware.

Frequently asked questions

ContextGem pulls structured data out of documents using LLMs. You define what to extract in plain language, and it returns values like fees, dates, clauses, and labels, each tied back to the paragraph or sentence it came from.