contextgem: the quick-start example ends inside an unterminated string
ContextGem: Effortless LLM extraction from documents
At a glance
- What is it?
- A Python framework that turns a document plus a natural-language description into typed extractions with references back to the source. The abstraction is clean and the governance around it is unusually heavy for a package still classified as beta, and the one worked example in the README stops mid-sentence.
- Who is it for?
- The two-level extraction model is the part worth stealing: separating where to look from what to pull means a document can be chunked once and reused, which is a better shape than one prompt per question. Before adopting it, read the documentation site rather than the README, since the README's only complete example is a single truncated line and the real one lives in a notebook under a development directory.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 3 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.
Star history
- shcherbak-ai/contextgem2,097 ★ · +97
| Repository | 2026-09-10 | 2026-11-23 |
|---|---|---|
| shcherbak-ai/contextgem | 2k | 2.1k |
97 Stars in the last 74 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The only complete worked example ends inside an unterminated string
The quick start builds a document from a consultancy agreement and then announces that it will extract anomalies from it, framing that as a task needing whole-document context rather than retrieval over passages.
The code that follows constructs the document by concatenating string literals. The last line of it is the payment clause, and it stops there, inside an unclosed quote, before the call is finished and before anything is extracted. As printed, the snippet is not valid Python.
That is not a nitpick about presentation. The fragment is the only narrative example in the document, and the section around it promises something quite specific: that unlike approaches which retrieve passages, this one analyses the entire document to find content that does not belong, with references and justifications attached.
The complete version is not in the documentation. It is a notebook in a development directory, linked from a hosted notebook service. The README's other Python fragments are self-contained and complete, and the simplest is a one-line document constructor with an ellipsis in place of real text.
So the gap is specific: a reader who wants to see what a justification or a reference mapping actually looks like in output has to leave the README, open a notebook, and run it.
Aspects locate text, Concepts pull values, and the Document object is mutated
The two-level model is the design. An aspect extracts a text segment, covering sections, topics, and themes, and can be organised hierarchically and combined with concepts. A concept extracts a specific data point with inference, and the documented types cover entities, insights, structured objects, classifications, numerical calculations, dates, ratings, and assessments.
Read as a pair, an aspect is a locator and a concept is a value. That separation is what lets one document be segmented once and reused for many questions, and it is why the framework describes both as things you can nest, with aspects containing concepts and aspects containing aspects.
The API reflects that: you create the document, then add aspects and concepts to that document instance, rather than passing a configuration object to a runner. The document is the accumulator.
The example pair makes the distinction concrete. An aspect named for a contract term and termination, describing clauses on that subject, and a concept asking whether the document is a non-disclosure agreement, described in plain language. One finds the region, the other returns a boolean derived from it.
There is a separate path for repeatable work, described as a reusable collection of predefined aspects and concepts that enables consistent extraction across multiple documents. So the two ways to use the library are a mutated document instance for one-off work and a reusable collection for consistency, and the documentation does not say which to prefer when.
The final step takes either an LLM or, for more demanding work, a group of them.
Five automations are promised and four appear in the result
The motivation paragraph names five things a developer would otherwise do by hand: writing extraction prompts, designing validation models, mapping outputs back to source references, orchestrating multi-step pipelines, and tracking usage across models.
The sentence immediately after says the framework handles all of them.
The result sentence that follows lists four: structured data with paragraph- and sentence-level references, automatic justifications, hierarchical multi-aspect extraction, and a unified, serializable document storage model.
Cross-checking the two lists, four of the five claimed automations reappear. Prompt generation becomes the automated dynamic prompts feature. Validation models become the automated data modelling feature. Reference mapping becomes granular reference mapping. Pipeline orchestration becomes the unified declarative pipeline.
Usage tracking does not reappear. There is no usage object, cost figure, or token count anywhere in the visible API, and none of the four stated results is about accounting. So the paragraph makes a five-item claim and the enumeration that a reader will read next makes a four-item one, with the difference being the one that matters most when you are running this against a paid endpoint.
That is a documentation observation rather than a claim that the feature is absent, since the documentation site may well describe it. It does mean the README cannot be used to decide whether cost visibility is included.
Eight of fifty-five keywords place a domain-agnostic library in legal work
The package metadata carries fifty-five keywords. Most are the vocabulary of the field, things like information extraction, large language models, structured data, and text processing.
Eight of them are not. There are six variants of the contract domain: contract analysis, contract automation, contract intelligence, contract management, contract parsing, and contract review. Add legal technology and financial technology and that is eight.
Meanwhile the library itself is domain-agnostic. The README's own examples are a consultancy agreement and a non-disclosure agreement, and the document class it names is a contract, an invoice, a report, or a curriculum vitae. So the examples happen to be legal while the abstraction is not.
The consequence is a mismatch between how the package presents itself and how it is likely to be found. A developer looking for contract tooling will find it, and so will a developer looking for a general extraction framework, because the general keywords are also present.
One keyword has no relationship to either. Neural segmentation is a term from medical and brain imaging work, and nothing in the documentation involves images of any kind beyond the mention that documents may contain visual content. It appears to be a leftover.
The list also includes the package's own name and two marketing-shaped entries, one claiming no prompt engineering and one claiming prompt-free, which are assertions rather than descriptions.
Three of the nine build tools come from one vendor, and one is by the author
The badge row in the README lists the tooling, and it is a long one: a package manager, a linter, a validation library, a type checker, a pre-commit framework, a dependency auditor, a sibling project by the same author, and a build backend.
Three of those come from a single vendor, which supplies the package manager, the linter, and the type checker. That is a coherent stack rather than a random selection, and using one vendor's tools across all three roles is a defensible choice for a project this size.
The dependency auditor is the interesting one. It checks that declared dependencies match what the code actually imports, which for a framework with a broad optional surface is the difference between a correct dependency list and one that accumulates packages nobody uses.
The sibling project by the same author is listed among tools rather than among dependencies, which is an unusual place for it. If the framework needs it at runtime, the dependency list in the metadata is where it should appear.
The repository contents match the badge row. Alongside the package directory, documentation, tests, and a lock file, there is a task file for Fabric, a markdown lint configuration, a citation file, two agent instruction files, a licence review configuration, a licences file, and a notice file.
Two agent instruction files and a task framework alongside nine development tools is the governance surface of a much older project than version 0.27 suggests.
A bounded interpreter range and a licence declared twice over
The interpreter requirement is a range with a ceiling: Python 3.10 up to but not including 3.15. Both ends are stated, which is more precise than most packages manage and means the project has thought about which interpreter versions it will actually be tested on.
Installation is two one-liners, with the first recommended:
uv add contextgemor
pip install -U contextgemNeither pins anything, and there is a lock file in the repository for anyone who wants to.
The licence is declared in the older table form, with the identifier as free text rather than as a modern expression. That form still works and is widely used, so it is a matter of currency rather than correctness.
The repository carries a licences file, a notice file, and a configuration for a licence-header review tool, plus a workflow that runs that review. For a single-licence Apache-2.0 package the notice file is the expected companion, since that licence asks for upstream notices to be carried forward.
The licences file is the one that adds a question. That filename is the convention used by tools that grant licences per path, which is a different model from one licence covering the whole distribution. Whether the two are reconciled somewhere in the tree is not visible from what is shown.
None of this is a red flag. It is a package that has spent attention on its licensing metadata, which is rarer than it should be, and the visible text simply does not say which arrangement is in force.
Version 0.27, still beta, released roughly monthly
The version in the package metadata is 0.27.0 and the newest release carries the same number, dated the same day as the last commit. That agreement is worth noting because the three projects most recently in this batch did not all manage it, and a package that tags on the commit it ships is doing the basic release hygiene right.
The cadence behind the number is monthly rather than incidental. Three visible releases are a patch in June, a minor in late July, and a minor in mid-August.
Against that, the project still declares itself as beta in its trove classifiers. Twenty-seven minor versions in, with a changelog file, a security policy, a code of conduct, and a citation file, it has the apparatus of a mature library and the self-description of an early one.
Nothing in the visible text explains which is the intent. The practical reading is that the API is still moving at a minor-version cadence, so a pin is worth more than a range, and the changelog is the file to read before upgrading rather than after.
Editorial conclusion
The two-level extraction model is the part worth stealing: separating where to look from what to pull means a document can be chunked once and reused, which is a better shape than one prompt per question. Before adopting it, read the documentation site rather than the README, since the README's only complete example is a single truncated line and the real one lives in a notebook under a development directory. Two things to verify against your own constraints. The framework's selling point is that reference mapping and validation models are handled for you, so check that the references point at spans you can re-verify, since a wrong reference that looks right is worse than no reference. And note the dependency surface, which is broad by choice and pinned by a constraints lock rather than by a single upper bound.
Frequently asked questions
What is shcherbak-ai/contextgem?
A Python framework for extracting structured data and insights from documents with an LLM, published to PyPI and licensed Apache-2.0. It targets Python 3.10 through 3.14, is classified as beta, and its stated outputs include paragraph- and sentence-level source references and automatic justifications.
What is the difference between an Aspect and a Concept in contextgem?
Aspects extract text segments such as sections, topics, and themes, and can be organised hierarchically. Concepts extract specific data points with inference, covering entities, insights, structured objects, classifications, numerical calculations, dates, ratings, and assessments.
How is contextgem installed?
With `uv add contextgem`, which is the recommended route, or with `pip install -U contextgem`. The framework is also available as a hosted notebook walkthrough of its quick start example.
Does contextgem map extractions back to the source document?
Yes. Granular reference mapping is one of the listed features, and the stated result is structured data carrying paragraph- and sentence-level references, together with automatic justifications attached to the extracted values.
What is an Extraction Pipeline in contextgem?
A reusable collection of predefined aspects and concepts for consistent extraction across multiple documents. The alternative is to add aspects and concepts directly to a Document instance, which the documentation presents as the one-off path rather than the reusable one.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/shcherbak-ai-contextgem)Star history chart for your README
[](https://hysenlabs.com/projects/shcherbak-ai-contextgem)Was this useful?