Classify how retrieved text supports, partially supports, contradicts, or does not contribute to an answer.
Features · Quick start · Statuses · Development · Releases
Features
- Two classification approaches: structured chat-model output and a TypeSafe system-one classifier.
- Traceable results: each result retains the original chunk and its stable identifier.
- Typed data: Pydantic models with frozen attributes validate inputs and outputs.
- Packaged prompts: Markdown and YAML prompt templates are available through Python APIs.
- Optional integrations: install only the provider dependencies you need.
Quick start
Requires Python 3.12 or newer. Install the OpenAI integration with your package manager:
# pip (inside your virtual environment)
python -m pip install "vestigia[openai]"
# uv (in a uv-managed project)
uv add "vestigia[openai]"
# Poetry (in a Poetry-managed project)
poetry add "vestigia[openai]"
Set OPENAI_API_KEY in your environment. Save the following example as
classify.py and run it with python classify.py (or uv run classify.py,
poetry run python classify.py).
This example sends data to the configured provider and may incur API charges.
import asyncio
from langchain_openai import ChatOpenAI
from vestigia.chunk_classification import Chunk
from vestigia.chunk_classification.langchain import ChatModelChunkClassifier
classifier = ChatModelChunkClassifier(
ChatOpenAI(model="gpt-4o-mini"),
)
async def classify_answer():
result = await classifier.classify(
query="What is the repayment term?",
answer="The plan lasts 60 months.",
chunks=[
Chunk(
id="repayment-term",
text="The repayment plan lasts 60 months.",
),
Chunk(
id="early-repayment",
text="Early repayment has no additional fee.",
),
],
)
for item in result.classifications:
print(item.chunk.id, item.status.value, item.explanation)
if __name__ == "__main__":
asyncio.run(classify_answer())
ChatModelChunkClassifier accepts any LangChain BaseChatModel that supports
structured output; the OpenAI integration above is one option.
Use a TypeSafe system-one model
Install the extra with python -m pip install "vestigia[typesafe]"
(uv add or poetry add work the same way) and set TYPESAFE_API_KEY.
Save this example as classify.py and run it with
python classify.py:
import asyncio
from langchain_typesafe import TypeSafeClassifier
from vestigia.chunk_classification import Chunk
from vestigia.chunk_classification.langchain import SystemOneModelChunkClassifier
async def classify_answer():
classifier = SystemOneModelChunkClassifier(TypeSafeClassifier())
result = await classifier.classify(
query="What is the repayment term?",
answer="The plan lasts 60 months.",
chunks=[Chunk(id="source-1", text="The plan lasts 60 months.")],
)
for item in result.classifications:
print(item.chunk.id, item.status.value, item.probabilities, item.confidence)
if __name__ == "__main__":
asyncio.run(classify_answer())
Like the chat-model example, this makes a real provider request. System-one results include per-status probabilities and confidence.
Use the data models directly
The package exports its domain models from vestigia.chunk_classification:
from vestigia.chunk_classification import (
ChatModelChunkClassification,
ChatModelChunksClassificationResult,
Chunk,
ChunkStatus,
)
chunk = Chunk(id="source-1", text="The plan lasts 60 months.")
result = ChatModelChunksClassificationResult(
classifications=(
ChatModelChunkClassification(
chunk=chunk,
status=ChunkStatus.USED,
explanation="The answer states the same repayment term.",
),
)
)
Classification statuses
| Status | Meaning |
|---|---|
used |
The answer states or faithfully paraphrases meaningful information from the chunk. |
partially_used |
The answer uses meaningful information but omits or incompletely represents other significant details. |
contradicted |
The answer makes a claim incompatible with information in the chunk. |
not_used |
No meaningful information from the chunk appears in the answer, and it is not contradicted. |
uncertain |
The available text does not support a reliable classification. |
Omission alone is not a contradiction. Both packaged prompts instruct the model to assess each chunk against the answer and avoid relying on external knowledge. The labels describe observable overlap and conflict, not proof of the generating model's internal reasoning or actual use of a retrieved chunk.
Classifiers and prompts
| API | Purpose | Optional dependency |
|---|---|---|
ChatModelChunkClassifier |
Classify chunks using a LangChain chat model with structured output. | openai, anthropic, or another installed LangChain chat integration |
SystemOneModelChunkClassifier |
Classify chunks using a TypeSafe system-one model and per-status criteria. | typesafe |
The adapters are exported from vestigia.chunk_classification.langchain.
ChunkClassifier is exported from vestigia.chunk_classification.classifier.
Load the packaged prompt templates directly when needed:
from vestigia.chunk_classification.prompts import (
load_chat_model_prompt,
load_system_one_prompt,
)
chat_prompt_text = load_chat_model_prompt()
system_one_template = load_system_one_prompt()
load_system_one_prompt() requires the typesafe extra, which includes
PyYAML.
Custom prompts
Pass a langchain_core.prompts.PromptTemplate as prompt= to the chat
classifier. Its available variables are query, answer, and chunks; the
last contains XML-escaped source text and identifiers. The model returns only
each chunk's chunk_id, status, and optional explanation; results reference
the original Chunk objects.
For the system-one classifier, pass a SystemOneModelTemplate:
from vestigia.chunk_classification import ChunkStatus, SystemOneModelTemplate
template = SystemOneModelTemplate(
state="Question: {query}\nAnswer: {answer}",
instruction="Evaluate the following evidence: {chunk}",
criteria={
ChunkStatus.USED: "Meaningful information appears in the answer.",
ChunkStatus.NOT_USED: "No meaningful information appears in the answer.",
},
)
The state template receives query and answer; the instruction template
receives each chunk's text as chunk. Criteria require at least two statuses.
Input and output contracts
- Chunk IDs must be unique within each call. Duplicates raise
ValueErrorbefore a provider is invoked. - An empty chunk sequence returns
classifications=()without a provider call. - Results follow input order and contain the original
Chunkobjects. Missing, extra, or duplicate response IDs raiseValueError. - System-one answers must be choice answers whose labels belong to the prompt's
criteria. Confidence and probability values must be finite and in
[0, 1]. The package does not normalize the distribution or require an exact sum of 1. - Backend, prompt-formatting, and Pydantic validation errors propagate to the caller; the package does not substitute partial or empty success responses.
- Model attributes are frozen and extra fields are rejected. Freezing is shallow: nested dictionaries remain mutable, and normal Pydantic type coercion applies.
Installation options
The PyPI distribution, Python import package, and GitHub repository are all
named vestigia.
Install the core models without provider integrations:
python -m pip install vestigia
Install optional integrations with python -m pip install "vestigia[<extra>]",
uv add "vestigia[<extra>]", or poetry add "vestigia[<extra>]":
| Extra | Includes |
|---|---|
openai |
LangChain OpenAI integration |
typesafe |
TypeSafe classifier and YAML prompt support |
anthropic |
LangChain Anthropic integration |
all |
All optional integrations |
ChatModelChunkClassifier accepts any LangChain BaseChatModel, so the
openai and anthropic extras are conveniences rather than requirements.
Development
Install uv, clone the repository, and install the test and classifier dependencies:
git clone https://github.com/Lorenzo-Gardini/vestigia.git
cd vestigia
uv sync --locked --group dev --all-extras
Run the test suite:
uv run --locked --group dev --all-extras pytest
The tests use real LangChain runnables and TypeSafe response models with mocked providers. They require neither API keys nor network access to a model. Documentation examples are tested without making real provider requests. GitHub Actions runs on pushes and pull requests, checking the base installation, each classifier extra separately, and the combined configuration on Python 3.12. It also builds distributions, validates their metadata and README, and checks imports and packaged resources from an isolated wheel installation.
For architecture and contribution guidance, see AGENTS.md.
Releasing to PyPI
Publishing uses PyPI Trusted Publishing: no PyPI API token needs to be stored in GitHub.
Publishing configuration
Releases upload through the pypi GitHub environment in this repository's
settings; configure required reviewers there for manual approval before an
upload. The vestigia PyPI project
trusts this GitHub publisher:
| Setting | Value |
|---|---|
| PyPI project name | vestigia |
| Owner | Lorenzo-Gardini |
| Repository | vestigia |
| Workflow filename | publish.yml |
| Environment | pypi |
Ensure the PyPI Trusted Publisher configuration uses the current repository, workflow, and environment values shown above.
Publish a version
-
Update
project.versionin pyproject.toml, runuv lock, and commit the version and lockfile together. -
Verify the tests and packaging locally:
uv run --locked --group dev --all-extras pytest uv build --no-sources uvx --from twine twine check --strict dist/*
Use a clean
dist/directory so old artifacts are not included. -
Merge the changes into the default branch and push them before releasing.
-
Publish a GitHub Release targeting that commit, with a tag exactly matching
v<project.version>(for example,v0.1.0). Creating a tag alone or saving a draft release does not publish to PyPI. -
The publishing workflow checks the version, runs all CI profiles, builds and validates the packages, then uploads those same artifacts to PyPI after any environment approval.
-
Confirm the new version on PyPI and install it in a fresh virtual environment:
python -m pip install "vestigia[openai]==0.1.0"
Replace
0.1.0with the version being verified.
PyPI releases cannot be overwritten. For a corrected artifact, bump the version and publish a new release.
License
Licensed under Apache-2.0.
Metadata
Release files for vestigia 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vestigia-0.1.0.tar.gz | 21.3 kB | With provenance | Details for vestigia-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vestigia-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for vestigia-0.1.0-py3-none-any.whl |
Total release size: 44.0 kB
Release files / vestigia-0.1.0.tar.gz
| Download URL | vestigia-0.1.0.tar.gz |
|---|---|
| Size | 21.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f993bed602a3034b47755e2d1b20754d5fed88632daa3182f926e86e716eb72c
|
|
BLAKE2b-256 checksum How to use checksums |
113651c4037971e2210257def8a52b411a2009ae3d9ca429962548fdfcf68e7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / vestigia-0.1.0-py3-none-any.whl
| Download URL | vestigia-0.1.0-py3-none-any.whl |
|---|---|
| Size | 22.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3d3220f8535f6dc63472ea9e5ab2bdd56505ca4c59562535424f39bebc03799
|
|
BLAKE2b-256 checksum How to use checksums |
753a9bf1fc59b5c01086386d45bf6dfc9f6510e512c24d1e649914b0d916b1e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logSecurity for vestigia 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for vestigia-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.