kbguard 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kbguard-0.1.0/.env.example +40 -0
- kbguard-0.1.0/.github/workflows/kbguard.yml +85 -0
- kbguard-0.1.0/.github/workflows/release.yml +95 -0
- kbguard-0.1.0/.github/workflows/test-publish.yml +77 -0
- kbguard-0.1.0/.gitignore +48 -0
- kbguard-0.1.0/LICENSE +201 -0
- kbguard-0.1.0/PKG-INFO +195 -0
- kbguard-0.1.0/README.md +101 -0
- kbguard-0.1.0/conftest.py +10 -0
- kbguard-0.1.0/contract_tests/conftest.py +226 -0
- kbguard-0.1.0/contract_tests/test_adapter_contract.py +98 -0
- kbguard-0.1.0/docker-compose.yml +36 -0
- kbguard-0.1.0/docs/getting-started/installation.md +54 -0
- kbguard-0.1.0/docs/getting-started/quickstart.md +82 -0
- kbguard-0.1.0/docs/guide/adapters/chroma.md +30 -0
- kbguard-0.1.0/docs/guide/adapters/custom-adapter.md +67 -0
- kbguard-0.1.0/docs/guide/adapters/langchain-llamaindex.md +40 -0
- kbguard-0.1.0/docs/guide/adapters/overview.md +69 -0
- kbguard-0.1.0/docs/guide/adapters/pgvector.md +48 -0
- kbguard-0.1.0/docs/guide/adapters/pinecone.md +40 -0
- kbguard-0.1.0/docs/guide/adapters/qdrant.md +50 -0
- kbguard-0.1.0/docs/guide/checks/chunking-damage.md +79 -0
- kbguard-0.1.0/docs/guide/checks/contradictions.md +70 -0
- kbguard-0.1.0/docs/guide/checks/custom-check.md +80 -0
- kbguard-0.1.0/docs/guide/checks/duplicates.md +46 -0
- kbguard-0.1.0/docs/guide/checks/overview.md +35 -0
- kbguard-0.1.0/docs/guide/checks/stale-versions.md +31 -0
- kbguard-0.1.0/docs/guide/configuration.md +154 -0
- kbguard-0.1.0/docs/guide/diff-and-ci.md +68 -0
- kbguard-0.1.0/docs/guide/evals/answer-metrics.md +43 -0
- kbguard-0.1.0/docs/guide/evals/golden-sets.md +32 -0
- kbguard-0.1.0/docs/guide/evals/judge-and-calibration.md +50 -0
- kbguard-0.1.0/docs/guide/evals/retrieval-metrics.md +31 -0
- kbguard-0.1.0/docs/guide/health-score.md +53 -0
- kbguard-0.1.0/docs/index.md +51 -0
- kbguard-0.1.0/docs/project/case-study.md +38 -0
- kbguard-0.1.0/docs/project/changelog.md +149 -0
- kbguard-0.1.0/docs/project/contributing.md +103 -0
- kbguard-0.1.0/docs/project/faq.md +23 -0
- kbguard-0.1.0/docs/project/roadmap.md +92 -0
- kbguard-0.1.0/docs/project/sample-audit-report.md +37 -0
- kbguard-0.1.0/docs/reference/cli.md +85 -0
- kbguard-0.1.0/examples/ci/kbguard-client-template.yml +61 -0
- kbguard-0.1.0/examples/eval_demo/evals/calibration.jsonl +4 -0
- kbguard-0.1.0/examples/eval_demo/kbguard.yaml +23 -0
- kbguard-0.1.0/examples/eval_demo/seed.py +76 -0
- kbguard-0.1.0/examples/eval_demo/toy_target.py +46 -0
- kbguard-0.1.0/examples/policy_corpus/README.md +36 -0
- kbguard-0.1.0/examples/policy_corpus/kbguard.yaml +22 -0
- kbguard-0.1.0/examples/policy_corpus/seed.py +200 -0
- kbguard-0.1.0/mkdocs.yml +76 -0
- kbguard-0.1.0/pyproject.toml +168 -0
- kbguard-0.1.0/src/kbguard/__init__.py +1 -0
- kbguard-0.1.0/src/kbguard/adapters/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/adapters/base.py +70 -0
- kbguard-0.1.0/src/kbguard/adapters/bridge_langchain.py +151 -0
- kbguard-0.1.0/src/kbguard/adapters/chroma.py +125 -0
- kbguard-0.1.0/src/kbguard/adapters/pgvector.py +191 -0
- kbguard-0.1.0/src/kbguard/adapters/pinecone.py +153 -0
- kbguard-0.1.0/src/kbguard/adapters/qdrant.py +134 -0
- kbguard-0.1.0/src/kbguard/checks/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/checks/base.py +61 -0
- kbguard-0.1.0/src/kbguard/checks/chunking_damage.py +269 -0
- kbguard-0.1.0/src/kbguard/checks/contradictions.py +358 -0
- kbguard-0.1.0/src/kbguard/checks/duplicates.py +204 -0
- kbguard-0.1.0/src/kbguard/checks/stale_versions.py +116 -0
- kbguard-0.1.0/src/kbguard/cli.py +502 -0
- kbguard-0.1.0/src/kbguard/config.py +191 -0
- kbguard-0.1.0/src/kbguard/evals/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/evals/golden.py +124 -0
- kbguard-0.1.0/src/kbguard/evals/metrics/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/evals/metrics/base.py +24 -0
- kbguard-0.1.0/src/kbguard/evals/metrics/deepeval_plugin.py +186 -0
- kbguard-0.1.0/src/kbguard/evals/metrics/ragas_plugin.py +212 -0
- kbguard-0.1.0/src/kbguard/evals/retrieval.py +115 -0
- kbguard-0.1.0/src/kbguard/evals/target.py +121 -0
- kbguard-0.1.0/src/kbguard/ingest/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/ingest/embeddings.py +76 -0
- kbguard-0.1.0/src/kbguard/ingest/exporter.py +48 -0
- kbguard-0.1.0/src/kbguard/ingest/metadata.py +112 -0
- kbguard-0.1.0/src/kbguard/ingest/snapshot.py +302 -0
- kbguard-0.1.0/src/kbguard/judge/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/judge/cache.py +47 -0
- kbguard-0.1.0/src/kbguard/judge/calibrate.py +94 -0
- kbguard-0.1.0/src/kbguard/judge/client.py +102 -0
- kbguard-0.1.0/src/kbguard/models.py +70 -0
- kbguard-0.1.0/src/kbguard/py.typed +0 -0
- kbguard-0.1.0/src/kbguard/registry.py +52 -0
- kbguard-0.1.0/src/kbguard/report/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/report/enrich.py +176 -0
- kbguard-0.1.0/src/kbguard/report/html.py +52 -0
- kbguard-0.1.0/src/kbguard/report/results.py +36 -0
- kbguard-0.1.0/src/kbguard/report/templates/report.html.j2 +210 -0
- kbguard-0.1.0/src/kbguard/scoring/__init__.py +0 -0
- kbguard-0.1.0/src/kbguard/scoring/diff.py +129 -0
- kbguard-0.1.0/src/kbguard/scoring/health.py +81 -0
- kbguard-0.1.0/tests/conftest.py +107 -0
- kbguard-0.1.0/tests/test_adapters_base.py +55 -0
- kbguard-0.1.0/tests/test_adapters_bridge_langchain.py +148 -0
- kbguard-0.1.0/tests/test_adapters_chroma.py +112 -0
- kbguard-0.1.0/tests/test_adapters_pgvector.py +142 -0
- kbguard-0.1.0/tests/test_adapters_pinecone.py +302 -0
- kbguard-0.1.0/tests/test_adapters_pinecone_live.py +87 -0
- kbguard-0.1.0/tests/test_adapters_qdrant.py +136 -0
- kbguard-0.1.0/tests/test_checks_chunking_damage.py +317 -0
- kbguard-0.1.0/tests/test_checks_contradictions.py +254 -0
- kbguard-0.1.0/tests/test_checks_contradictions_live.py +70 -0
- kbguard-0.1.0/tests/test_checks_duplicates.py +235 -0
- kbguard-0.1.0/tests/test_checks_stale_versions.py +207 -0
- kbguard-0.1.0/tests/test_cli.py +178 -0
- kbguard-0.1.0/tests/test_cli_evals.py +410 -0
- kbguard-0.1.0/tests/test_config.py +154 -0
- kbguard-0.1.0/tests/test_evals_golden.py +279 -0
- kbguard-0.1.0/tests/test_evals_metrics_deepeval_plugin.py +236 -0
- kbguard-0.1.0/tests/test_evals_metrics_ragas_plugin.py +126 -0
- kbguard-0.1.0/tests/test_evals_retrieval.py +257 -0
- kbguard-0.1.0/tests/test_evals_target.py +267 -0
- kbguard-0.1.0/tests/test_examples_policy_corpus.py +104 -0
- kbguard-0.1.0/tests/test_ingest_embeddings.py +117 -0
- kbguard-0.1.0/tests/test_ingest_exporter.py +105 -0
- kbguard-0.1.0/tests/test_ingest_metadata.py +116 -0
- kbguard-0.1.0/tests/test_ingest_snapshot.py +275 -0
- kbguard-0.1.0/tests/test_judge_cache.py +45 -0
- kbguard-0.1.0/tests/test_judge_calibrate.py +146 -0
- kbguard-0.1.0/tests/test_judge_client.py +178 -0
- kbguard-0.1.0/tests/test_models.py +72 -0
- kbguard-0.1.0/tests/test_plugin_registration.py +38 -0
- kbguard-0.1.0/tests/test_registry.py +68 -0
- kbguard-0.1.0/tests/test_report_enrich.py +214 -0
- kbguard-0.1.0/tests/test_report_html.py +203 -0
- kbguard-0.1.0/tests/test_report_results.py +75 -0
- kbguard-0.1.0/tests/test_scoring_diff.py +268 -0
- kbguard-0.1.0/tests/test_scoring_health.py +161 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copy this file to .env and fill in real values there. .env is gitignored
|
|
2
|
+
# and never committed — only the variable *names* belong in version
|
|
3
|
+
# control, never the values (same principle as kbguard.yaml's
|
|
4
|
+
# api_key_env: fields, which hold a variable name, not a secret).
|
|
5
|
+
#
|
|
6
|
+
# .env is loaded automatically by the repo-root conftest.py before any
|
|
7
|
+
# test runs (python-dotenv) — nothing else in kbguard reads it.
|
|
8
|
+
|
|
9
|
+
# Remote Docker host for pgvector/Qdrant contract tests, if not localhost.
|
|
10
|
+
# See docs/project/contributing.md.
|
|
11
|
+
# KBGUARD_TEST_PG_HOST=
|
|
12
|
+
# KBGUARD_TEST_PG_PORT=5434
|
|
13
|
+
# KBGUARD_TEST_QDRANT_HOST=
|
|
14
|
+
# KBGUARD_TEST_QDRANT_PORT=6333
|
|
15
|
+
|
|
16
|
+
# Pinecone: needed only for tests/test_adapters_pinecone_live.py, which is
|
|
17
|
+
# skipped automatically when these aren't set. Free "Starter" tier is
|
|
18
|
+
# enough — see docs/guide/adapters/pinecone.md.
|
|
19
|
+
# PINECONE_API_KEY=
|
|
20
|
+
# PINECONE_TEST_INDEX=
|
|
21
|
+
|
|
22
|
+
# judge.model in kbguard.yaml is a plain litellm model string -- only the
|
|
23
|
+
# ONE matching provider's key below is actually needed, based on whatever
|
|
24
|
+
# you set judge.model to (e.g. judge.model: xai/grok-4.5 needs only
|
|
25
|
+
# XAI_API_KEY; judge.model: ollama/llama3 needs none of these at all,
|
|
26
|
+
# since Ollama runs locally with no API key). Fill in only the one(s)
|
|
27
|
+
# you're actually going to use.
|
|
28
|
+
# xAI / Grok -- judge.model: xai/grok-4.5 (or whatever's current on x.ai's pricing page)
|
|
29
|
+
# XAI_API_KEY=
|
|
30
|
+
# Groq (fast/cheap inference for open models -- NOT the same company as
|
|
31
|
+
# Grok/xAI, confusingly similar name) -- judge.model: groq/qwen/qwen3.8-27b
|
|
32
|
+
# recommended over groq/openai/gpt-oss-120b: hand-verified both are real,
|
|
33
|
+
# callable model names, but at temperature=0 gpt-oss-120b consistently
|
|
34
|
+
# misjudges a real planted contradiction that qwen3.8-27b consistently
|
|
35
|
+
# gets right (see tests/conftest.py's real_judge fixture)
|
|
36
|
+
# GROQ_API_KEY=
|
|
37
|
+
# OpenAI -- judge.model: gpt-4o-mini
|
|
38
|
+
# OPENAI_API_KEY=
|
|
39
|
+
# Anthropic -- judge.model: anthropic/claude-3-5-sonnet-...
|
|
40
|
+
# ANTHROPIC_API_KEY=
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
name: kbguard CI
|
|
2
|
+
|
|
3
|
+
# This workflow tests kbguard's OWN source — unit tests, contract tests
|
|
4
|
+
# against real pgvector/Qdrant/Chroma backends, lint, and strict types.
|
|
5
|
+
# It is NOT the CI template a client runs kbguard against their own
|
|
6
|
+
# knowledge base with — that one lives at
|
|
7
|
+
# examples/ci/kbguard-client-template.yml, kept clearly separate so the
|
|
8
|
+
# two "same filename pattern, different job" workflows never get
|
|
9
|
+
# conflated (spec section 12's design note).
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
push:
|
|
13
|
+
branches: [main]
|
|
14
|
+
pull_request:
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
test:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
services:
|
|
21
|
+
postgres:
|
|
22
|
+
image: pgvector/pgvector:pg16
|
|
23
|
+
env:
|
|
24
|
+
POSTGRES_USER: kbguard
|
|
25
|
+
POSTGRES_PASSWORD: kbguard
|
|
26
|
+
POSTGRES_DB: kbguard_test
|
|
27
|
+
ports:
|
|
28
|
+
# Host port matches this repo's own docker-compose.yml and the
|
|
29
|
+
# test suite's default (KBGUARD_TEST_PG_PORT=5434) exactly, so
|
|
30
|
+
# no extra env vars are needed just to run in CI.
|
|
31
|
+
- 5434:5432
|
|
32
|
+
options: >-
|
|
33
|
+
--health-cmd pg_isready
|
|
34
|
+
--health-interval 10s
|
|
35
|
+
--health-timeout 5s
|
|
36
|
+
--health-retries 5
|
|
37
|
+
qdrant:
|
|
38
|
+
image: qdrant/qdrant
|
|
39
|
+
ports:
|
|
40
|
+
- 6333:6333
|
|
41
|
+
|
|
42
|
+
strategy:
|
|
43
|
+
matrix:
|
|
44
|
+
python-version: ["3.10", "3.12"]
|
|
45
|
+
|
|
46
|
+
steps:
|
|
47
|
+
- uses: actions/checkout@v4
|
|
48
|
+
|
|
49
|
+
- uses: actions/setup-python@v5
|
|
50
|
+
with:
|
|
51
|
+
python-version: ${{ matrix.python-version }}
|
|
52
|
+
|
|
53
|
+
- name: Install kbguard with every extra the test suite needs
|
|
54
|
+
run: pip install -e ".[all]"
|
|
55
|
+
|
|
56
|
+
# spaCy's language models are NOT a regular pip dependency pulled in
|
|
57
|
+
# by `pip install spacy` (or the `nlp` extra above) -- they're a
|
|
58
|
+
# separate download, required at runtime by checks/contradictions.py
|
|
59
|
+
# and exercised directly by its tests. Missed entirely until this
|
|
60
|
+
# workflow's first real run: the local dev venv already had this
|
|
61
|
+
# model downloaded by hand from early in the build, so every local
|
|
62
|
+
# `pytest` run passed silently while CI never actually had it.
|
|
63
|
+
- name: Download spaCy's small English model
|
|
64
|
+
run: python -m spacy download en_core_web_sm
|
|
65
|
+
|
|
66
|
+
- name: ruff
|
|
67
|
+
run: ruff check src tests contract_tests examples conftest.py
|
|
68
|
+
|
|
69
|
+
- name: mypy --strict
|
|
70
|
+
run: mypy src/kbguard
|
|
71
|
+
|
|
72
|
+
- name: pytest (unit + contract tests, real pgvector/Qdrant/Chroma)
|
|
73
|
+
run: pytest -q
|
|
74
|
+
env:
|
|
75
|
+
# Pinecone's live test (tests/test_adapters_pinecone_live.py)
|
|
76
|
+
# skips cleanly without these — no account needed for CI to
|
|
77
|
+
# pass; set them as repo secrets only if you want that
|
|
78
|
+
# coverage running here too.
|
|
79
|
+
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
|
|
80
|
+
PINECONE_TEST_INDEX: ${{ secrets.PINECONE_TEST_INDEX }}
|
|
81
|
+
|
|
82
|
+
- name: mkdocs build --strict
|
|
83
|
+
run: |
|
|
84
|
+
pip install -e ".[docs]"
|
|
85
|
+
mkdocs build --strict
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Publishes a tagged release to the real PyPI index via Trusted Publishing
|
|
4
|
+
# (OIDC — no stored API token, confirmed as PyPA's own current recommended
|
|
5
|
+
# approach before writing this: https://docs.pypi.org/trusted-publishers/).
|
|
6
|
+
# This workflow does NOT publish anything by itself. Nothing uploads until
|
|
7
|
+
# a human explicitly creates a GitHub Release (which itself requires a
|
|
8
|
+
# tag) — a deliberate, one-click-away-but-not-automatic trigger, not "every
|
|
9
|
+
# push publishes."
|
|
10
|
+
#
|
|
11
|
+
# One-time manual setup required before this can work at all (done once,
|
|
12
|
+
# on pypi.org, by whoever owns the PyPI account — not something a CI
|
|
13
|
+
# workflow or an agent can do on your behalf):
|
|
14
|
+
# 1. Create the `kbguard` project on PyPI (or reserve the name) if it
|
|
15
|
+
# doesn't exist yet.
|
|
16
|
+
# 2. On the project's "Publishing" settings page, add a trusted
|
|
17
|
+
# publisher: GitHub owner "devbyanoop", repository "kbguard",
|
|
18
|
+
# workflow filename "release.yml", environment name "pypi" (must
|
|
19
|
+
# match exactly, including the environment below).
|
|
20
|
+
# 3. In this repo's GitHub settings, create an environment named
|
|
21
|
+
# "pypi" (Settings → Environments) — add protection rules (e.g.
|
|
22
|
+
# required reviewers) if you want a human approval step before
|
|
23
|
+
# every publish, which is recommended for a one-way action like
|
|
24
|
+
# this.
|
|
25
|
+
# See docs.pypi.org/trusted-publishers/adding-a-publisher/ for the exact
|
|
26
|
+
# current PyPI-side steps (these change rarely but are PyPI's own UI, not
|
|
27
|
+
# this repo's to document precisely).
|
|
28
|
+
|
|
29
|
+
on:
|
|
30
|
+
release:
|
|
31
|
+
types: [published]
|
|
32
|
+
|
|
33
|
+
jobs:
|
|
34
|
+
build:
|
|
35
|
+
name: Build and verify the distribution
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
|
|
40
|
+
- uses: actions/setup-python@v5
|
|
41
|
+
with:
|
|
42
|
+
python-version: "3.12"
|
|
43
|
+
|
|
44
|
+
- name: Install kbguard with every extra the test suite needs
|
|
45
|
+
run: pip install -e ".[all]"
|
|
46
|
+
|
|
47
|
+
# See kbguard.yml's identical step for why this is needed separately
|
|
48
|
+
# from the pip install above -- spaCy's model is not a regular pip
|
|
49
|
+
# dependency.
|
|
50
|
+
- name: Download spaCy's small English model
|
|
51
|
+
run: python -m spacy download en_core_web_sm
|
|
52
|
+
|
|
53
|
+
- name: ruff
|
|
54
|
+
run: ruff check src tests contract_tests examples conftest.py
|
|
55
|
+
|
|
56
|
+
- name: mypy --strict
|
|
57
|
+
run: mypy src/kbguard
|
|
58
|
+
|
|
59
|
+
- name: pytest (unit + contract tests; real external services/APIs skip cleanly without credentials)
|
|
60
|
+
run: pytest -q
|
|
61
|
+
|
|
62
|
+
- name: Build sdist and wheel
|
|
63
|
+
run: |
|
|
64
|
+
pip install --upgrade build twine
|
|
65
|
+
python -m build
|
|
66
|
+
twine check dist/*
|
|
67
|
+
|
|
68
|
+
- name: Upload the built distribution
|
|
69
|
+
uses: actions/upload-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: dist
|
|
72
|
+
path: dist/
|
|
73
|
+
|
|
74
|
+
publish:
|
|
75
|
+
name: Publish to PyPI
|
|
76
|
+
needs: build
|
|
77
|
+
runs-on: ubuntu-latest
|
|
78
|
+
# Matches the trusted-publisher configuration's "environment name"
|
|
79
|
+
# exactly (see the setup note above) — PyPI checks this as part of
|
|
80
|
+
# verifying the OIDC token actually came from the workflow/environment
|
|
81
|
+
# it was told to trust, not just from this repo in general.
|
|
82
|
+
environment:
|
|
83
|
+
name: pypi
|
|
84
|
+
url: https://pypi.org/p/kbguard
|
|
85
|
+
permissions:
|
|
86
|
+
id-token: write # the one thing trusted publishing actually needs — no secrets.PYPI_API_TOKEN anywhere
|
|
87
|
+
steps:
|
|
88
|
+
- name: Download the distribution built and verified above
|
|
89
|
+
uses: actions/download-artifact@v4
|
|
90
|
+
with:
|
|
91
|
+
name: dist
|
|
92
|
+
path: dist/
|
|
93
|
+
|
|
94
|
+
- name: Publish to PyPI
|
|
95
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
name: Publish to TestPyPI
|
|
2
|
+
|
|
3
|
+
# Rehearses the real release.yml's Trusted Publishing mechanism against
|
|
4
|
+
# the TestPyPI index before anything goes to the real PyPI index. Manually
|
|
5
|
+
# triggered (workflow_dispatch) only -- a TestPyPI upload is still a real,
|
|
6
|
+
# visible, one-way action (a given version string can never be
|
|
7
|
+
# re-uploaded to the same index, same restriction as real PyPI), so this
|
|
8
|
+
# never fires on its own.
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
name: Build and verify the distribution
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
|
|
24
|
+
- name: Install kbguard with every extra the test suite needs
|
|
25
|
+
run: pip install -e ".[all]"
|
|
26
|
+
|
|
27
|
+
# See kbguard.yml's identical step for why this is needed separately
|
|
28
|
+
# from the pip install above -- spaCy's model is not a regular pip
|
|
29
|
+
# dependency.
|
|
30
|
+
- name: Download spaCy's small English model
|
|
31
|
+
run: python -m spacy download en_core_web_sm
|
|
32
|
+
|
|
33
|
+
- name: ruff
|
|
34
|
+
run: ruff check src tests contract_tests examples conftest.py
|
|
35
|
+
|
|
36
|
+
- name: mypy --strict
|
|
37
|
+
run: mypy src/kbguard
|
|
38
|
+
|
|
39
|
+
- name: pytest (unit + contract tests; real external services/APIs skip cleanly without credentials)
|
|
40
|
+
run: pytest -q
|
|
41
|
+
|
|
42
|
+
- name: Build sdist and wheel
|
|
43
|
+
run: |
|
|
44
|
+
pip install --upgrade build twine
|
|
45
|
+
python -m build
|
|
46
|
+
twine check dist/*
|
|
47
|
+
|
|
48
|
+
- name: Upload the built distribution
|
|
49
|
+
uses: actions/upload-artifact@v4
|
|
50
|
+
with:
|
|
51
|
+
name: dist
|
|
52
|
+
path: dist/
|
|
53
|
+
|
|
54
|
+
publish:
|
|
55
|
+
name: Publish to TestPyPI
|
|
56
|
+
needs: build
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
# Matches the trusted-publisher configuration's "environment name"
|
|
59
|
+
# exactly -- same requirement as release.yml's "pypi" environment,
|
|
60
|
+
# kept as a separate environment name so a TestPyPI trusted publisher
|
|
61
|
+
# can never be confused with the real-PyPI one.
|
|
62
|
+
environment:
|
|
63
|
+
name: testpypi
|
|
64
|
+
url: https://test.pypi.org/p/kbguard
|
|
65
|
+
permissions:
|
|
66
|
+
id-token: write # the one thing trusted publishing actually needs -- no secrets.TESTPYPI_API_TOKEN anywhere
|
|
67
|
+
steps:
|
|
68
|
+
- name: Download the distribution built and verified above
|
|
69
|
+
uses: actions/download-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: dist
|
|
72
|
+
path: dist/
|
|
73
|
+
|
|
74
|
+
- name: Publish to TestPyPI
|
|
75
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
76
|
+
with:
|
|
77
|
+
repository-url: https://test.pypi.org/legacy/
|
kbguard-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# kbguard runtime data — snapshots contain client text, never commit
|
|
2
|
+
.kbguard/
|
|
3
|
+
|
|
4
|
+
# Python
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*.egg-info/
|
|
8
|
+
.eggs/
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
|
|
14
|
+
# Test / tool caches
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.mypy_cache/
|
|
17
|
+
.ruff_cache/
|
|
18
|
+
.coverage
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# Editors / OS
|
|
22
|
+
.vscode/
|
|
23
|
+
.idea/
|
|
24
|
+
.DS_Store
|
|
25
|
+
Thumbs.db
|
|
26
|
+
#Do not commit following folders
|
|
27
|
+
Plan/
|
|
28
|
+
# Env files that may hold secrets (judge model keys, DB creds)
|
|
29
|
+
.env
|
|
30
|
+
.env.*
|
|
31
|
+
!.env.example
|
|
32
|
+
|
|
33
|
+
# MkDocs build output (published separately, not committed to main)
|
|
34
|
+
site/
|
|
35
|
+
|
|
36
|
+
# Generated demo data — reproducible via examples/policy_corpus/seed.py
|
|
37
|
+
examples/policy_corpus/chroma_data/
|
|
38
|
+
|
|
39
|
+
# Generated demo data -- reproducible via examples/eval_demo/seed.py
|
|
40
|
+
examples/eval_demo/chroma_data/
|
|
41
|
+
|
|
42
|
+
# Generated golden set -- judge-generated content from a real LLM call,
|
|
43
|
+
# reproducible via `kbguard golden generate`, not stable data. Named
|
|
44
|
+
# individually, not as a whole-directory pattern: a directory-level
|
|
45
|
+
# ignore (trailing slash) stops git from even looking inside it, so a
|
|
46
|
+
# `!` exception for calibration.jsonl (hand-written, kept) wouldn't work.
|
|
47
|
+
examples/eval_demo/evals/golden_review.csv
|
|
48
|
+
examples/eval_demo/evals/golden.jsonl
|
kbguard-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the
|
|
44
|
+
purposes of this License, Derivative Works shall not include works
|
|
45
|
+
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
+
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing
|
|
141
|
+
the origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Anoop Singh
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|