In short.
ContextGem is a Python library for developers turning individual documents into structured data, but extraction quality still depends on the chosen models and documents. It combines topic-based passages, typed values and optional source references, using language models for open answers and decision models for closed choices with probabilities. The supplied documentation gives useful implementation examples, but establishes no measured accuracy, latency or operating cost.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage is limited to README.md at [https://github.com/shcherbak-ai/contextgem/blob/main/README.md], represented by captured revision 49c7d81ccb18f02a5d5382422454561320da9b27, plus its accompanying LICENSE and NOTICE. All three supplied texts are covered. Linked pages, implementation files, package metadata, fixtures, dependencies and test artifacts were not inspected. Nothing was installed or executed; documented examples do not establish operational results.
The overview
Identity
ContextGem is an open-source Python extraction framework developed by Sergii Shcherbak and attributed to Shcherbak AI AS. The source page is [https://github.com/shcherbak-ai/contextgem/blob/main/README.md]. The README links documentation at [https://contextgem.shcherbak.ai/].
Its central distinction is between aspects, which return document passages about a topic, and concepts, which return typed values derived from the text.
Assessment
ContextGem appears useful when an application needs repeatable extraction definitions, structured results and passages that a person can inspect. Contract clauses, document metadata and predefined classifications are concrete examples in the README.
Its value is the surrounding extraction machinery: generated prompts, validation, source mapping, reusable pipelines and model routing. The supplied material does not establish how accurately that machinery extracts facts from a particular document collection.
Users
The primary audience is developers building document-processing applications or adding extraction to an agent workflow. Beginners need enough Python to create objects, install packages and configure model access; experienced developers can use nested extraction definitions, model roles and fallbacks.
The README describes extracting metadata during ingestion, returning sourced values through an agent tool, and answering closed questions at workflow decision points. Searching and querying an entire collection requires additional tooling.
Capabilities
Documented output types include text, numbers, dates, booleans, labels, ratings and JSON objects. Aspects and sub-aspects organise relevant passages, while concepts can extract values from a whole document or an aspect. Extraction definitions can be reused and serialised.
LLM extraction supports text and images, with optional paragraph or sentence references and justifications. Decision models work on text and support aspects plus Boolean, label and rating concepts, returning answer probabilities and configurable thresholds. Model groups route work by role and support fallbacks.
The optional Docling integration converts files into ContextGem documents while retaining structural context and page information. The README illustrates table rows retaining column headers and extracted items carrying page references.
Using it
Requirements
ContextGem requires Python and access to an appropriate cloud or local model. The README says its described 1.0 release drops Python 3.10 support, but the supplied text does not state the complete supported Python version range.
The cloud examples obtain credentials from CONTEXTGEM_OPENAI_API_KEY or CONTEXTGEM_TYPESAFE_API_KEY. Local hardware requirements and complete provider configuration requirements are unknown. File conversion requires the optional Docling extra; some formats also need external software, including LibreOffice for DOC, PPT, XLS and RTF.
Mechanism
Content enters a Document as text, images or a converted Docling document. Developers attach descriptions of aspects and concepts, then call an extraction method. An aspect returns original passages; a concept returns values such as a date, classification or structured object.
An LLM generates answers that ContextGem validates into typed items. A decision model supplies probabilities over predefined answers. A model group can assign these tasks to different model roles.
Within the text being analysed, ContextGem processes every paragraph together or in configured batches rather than using retrieval to select passages. This removes retrieval ranking as a reason to exclude a passage, but does not guarantee that a model recognises every relevant fact.
Setup
The documented installation command is uv add contextgem, with pip install -U contextgem as an alternative. File conversion adds the optional dependency through uv add "contextgem[docling]".
The basic sequence is to create a Document, add Aspect and concept definitions, configure DocumentLLM or DocumentDecisionModel with model access, and call extract_all(doc). For files, the example converts a file with DocumentConverter().convert(...) and passes result.document to Document.from_docling(). Successful installation and model compatibility in a particular environment are not established by these instructions.
Example
The LLM example defines Payment terms as an Aspect and Anomalies as a StringConcept in a consultancy agreement. Its documented output contains a payment paragraph and descriptions of two deliberately implausible statements, with sentence references and brief justifications enabled.
The decision-model example asks whether either party can terminate without cause and classifies the notice form using predefined labels. It shows a True answer and a Written label, accompanied by probabilities. These are author-supplied example outputs, not independently reproduced results or accuracy measurements.
Assessment & evidence
Limitations
ContextGem does not search a corpus or answer queries across documents. Decision models are limited to supported closed questions from text, while open values and image extraction require an appropriate LLM.
The README warns that smaller local LLMs may struggle to follow detailed extraction instructions. Typed validation can establish that an answer has the expected form without establishing that it is factually correct. The supplied probabilities do not establish calibration, meaning how reliably probability values correspond to real-world correctness.
File conversion introduces format-specific dependencies. Practical document limits, throughput, memory requirements and provider data-retention terms are unknown from the supplied evidence.
Reasoning
The design offers a useful separation between finding passages and deriving values. Source references can help a reviewer inspect an answer, while reusable definitions can reduce repeated prompt and validation work. Those benefits follow from the documented design; their practical size has not been measured here.
Choosing different models for open and closed questions creates another design trade-off: lower-cost classification may be possible, but suitability depends on the questions and documents. A generated justification explains an answer without proving it, and a probability threshold needs validation for its intended task.
Alternatives
For searching or querying a document collection, the README points to RAG frameworks such as LlamaIndex and Haystack. Their features, costs and relative performance are not assessed in the supplied evidence.
The README also describes a complementary arrangement: ContextGem extracts metadata into an index or database during ingestion, allowing an agent to find documents using that metadata.
Evidence
The first-party README supplies installation commands, Python examples and an account of its testing approach. It reports replayed model responses, property tests using malformed generated outputs, and reference-answer evaluations against quality and cost baselines. Narrative comparisons reportedly use Jev after checks on known verdicts.
Underlying implementation files, evaluation cases, numerical scores, test logs and security scan reports are absent. Reported testing and scanning therefore remain author descriptions; accuracy, robustness, security and performance were not independently assessed.
The immutable README source is [https://raw.githubusercontent.com/shcherbak-ai/contextgem/49c7d81ccb18f02a5d5382422454561320da9b27/README.md]. Linked documentation and other repository files are outside the supplied evidence.
Access & freshness
Costs
The library is described as free and open source. Model access and local inference infrastructure can introduce separate operating costs. No numerical provider prices, per-document costs or measured savings are supplied, so actual cost is unknown.
The README links usage and cost statistics, and NOTICE lists genai-prices for automatic cost estimation. Its descriptions of decision models as fast and inexpensive are not accompanied by comparative measurements in the supplied material.
Rights
ContextGem is distributed under Apache License 2.0. Its terms permit use, modification and redistribution. Redistribution requires a licence copy, preservation of applicable source notices, prominent change notices in modified files and applicable NOTICE attributions.
The licence provides no warranty and grants no general trademark rights. NOTICE attributes the software to Shcherbak AI AS and Sergii Shcherbak and lists third-party components that may have separate licences. The complete licence terms for those dependencies are not supplied.
Freshness
The supplied snapshot was captured on 2026-11-14 at 13:58:15.704 UTC from revision 49c7d81ccb18f02a5d5382422454561320da9b27. It describes decision models as new in 1.0 and warns of renamed or removed APIs, changed defaults and dropped Python 3.10 support when upgrading from 0.x.
A release date, latest published package version and subsequent repository changes are unknown. The README links a migration guide at [https://contextgem.shcherbak.ai/migration_v1/], but its contents are not supplied.
Actions
For an initial evaluation, define one aspect and a few typed concepts on representative documents with manually checked answers. Check missing facts, incorrect values and whether references actually support each answer. Add file conversion when needed and inspect table context and page references.
Compare a decision model with an LLM on the same closed questions before choosing thresholds. Record model identity, document length, usage, cost and response time. Confirm the supported Python version and provider configuration, and use the migration guide when moving from 0.x.
