Skip to main content

Pre-embedding data governance layer for AI systems

Project description

Precept SDK

The pre-embedding data governance layer for AI systems.

Precept sits between your raw data and AI memory — enforcing security, privacy, and compliance rules before anything gets embedded into a vector database.

Installation

pip install -e .
python -m spacy download en_core_web_sm

Quick Start

from precept import PreceptGuard

# Initialize with a policy
guard = PreceptGuard(policy='gdpr')

# Sanitize text before embedding
result = guard.sanitize('John Doe email is john@test.com phone 08012345678')

print(result.clean_text)
# Output: 'PERSON_1 email is EMAIL_1 phone PHONE_1'

print(result.detections)
# List of Detection objects showing what was found and replaced

print(result.compliance_status)
# {'gdpr': True}

print(result.tokens_consumed)
# Word count of the processed text

print(result.audit_id)
# UUID for this sanitization event

Policies

Precept ships with pre-built compliance policy presets:

Policy What It Redacts Bias Mode Quality
pii Names, emails, phones, SSNs, credit cards, IPs Off Off
gdpr All PII + dates + proprietary terms Flag On
hipaa All 18 PHI categories (names, dates, SSNs, emails, phones, etc.) Remove On
ndpr GDPR-equivalent + Nigerian ID patterns (NIN, BVN) Flag On

Using a single policy

guard = PreceptGuard(policy='hipaa')
result = guard.sanitize(clinical_note)

Using multiple policies

guard = PreceptGuard(policies=['gdpr', 'hipaa'])
result = guard.sanitize(document)
# result.compliance_status -> {'gdpr': True, 'hipaa': True}

Custom proprietary terms

guard = PreceptGuard(
    policy='gdpr',
    custom_terms=['Project Apollo', 'Operation X', 'AcmeCorp']
)
result = guard.sanitize('The Project Apollo launch is scheduled for Q3.')
# 'Project Apollo' replaced with 'PROPRIETARY_1'

Multi-tenant access control

guard = PreceptGuard(policy='gdpr', tenant_id='customer_123')
result = guard.sanitize(document)
# result.clean_text ends with [PRECEPT_TENANT: <hash>]
# result.tenant_tag contains the 16-char SHA256 hash

Bias detection

GDPR and NDPR policies flag biased sentences; HIPAA removes them:

guard = PreceptGuard(policy='hipaa')
result = guard.sanitize('The patient recovered well. A nurse used a slur.')
# Sentence with slur is removed in HIPAA mode (bias_mode='remove')
print(result.bias_flags)  # List of flagged sentences

Data quality checks

Quality checks run automatically with GDPR, HIPAA, and NDPR policies:

guard = PreceptGuard(policy='gdpr')
result = guard.sanitize('')
print(result.is_safe)           # False — empty text
print(result.quality_report)    # QualityReport with details

API Key (Optional in Phase 1)

If you have a Precept API key, pass it to enable usage tracking:

guard = PreceptGuard(api_key='prct_live_xxxx', policy='gdpr')

Without an API key, the SDK works fully offline — all detection and redaction happens locally.

Running Tests

pip install -e ".[dev]"
python -m spacy download en_core_web_sm
pytest tests/ -v

Project Structure

precept-sdk/
  precept/
    __init__.py          # Public API — exports PreceptGuard
    guard.py             # Core PreceptGuard class
    models.py            # Pydantic data models
    client.py            # HTTP client for API calls
    detectors/
      pii.py             # PII detection (spaCy + regex)
      proprietary.py     # Proprietary term detection
      bias.py            # Bias and toxicity detection
      quality.py         # Data quality checks
      access.py          # Multi-tenant access control
      data/
        bias_terms.txt   # Curated bias term wordlist
    policies/
      base.py            # Base policy class
      gdpr.py            # GDPR policy preset
      hipaa.py           # HIPAA policy preset
      ndpr.py            # NDPR policy preset
  tests/
    test_guard.py        # Guard integration tests
    test_pii.py          # PII detector unit tests
    test_all_modules.py  # Bias, quality, access, full pipeline tests
  setup.py
  README.md

Dependencies

  • spacy>=3.7.0 + en_core_web_sm model
  • pydantic>=2.0
  • httpx>=0.24

Phase 1 — What's Built

  • PII detection and redaction (names, emails, phones, SSNs, credit cards, IPs, dates)
  • Proprietary term detection with custom term lists
  • GDPR, HIPAA, and NDPR compliance policy presets
  • Semantic placeholder replacements (PERSON_1, EMAIL_1, etc.)
  • Local audit ID generation
  • Stub API client (fully connected in Phase 2)

Phase 4 — What's New

  • Bias detection: Curated wordlist matching for discriminatory terms with flag/remove modes
  • Data quality checks: Empty text, too-short, encoding errors, duplicate detection (session-scoped)
  • Multi-tenant access control: SHA256 tenant tagging, isolation verification
  • Extended SanitizeResult: is_safe, quality_report, bias_flags, tenant_tag fields
  • Updated policy presets: GDPR/NDPR flag bias, HIPAA removes bias, all run quality checks
  • Full pipeline: Quality → PII → Proprietary → Bias → Access control in one sanitize() call

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

precept_ai_sdk-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

precept_ai_sdk-0.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file precept_ai_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: precept_ai_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for precept_ai_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39d1232584f95a40c393f490c52725b3439638aa63d1b0b30673273647e3d0aa
MD5 f41f73f73302074c1be4842f3cbfe89e
BLAKE2b-256 b6eaa60d223784edd05dd247c5faca40053b443b8595104a7f81bf6d96e8790b

See more details on using hashes here.

File details

Details for the file precept_ai_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: precept_ai_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for precept_ai_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5602caa19d620332bba5da220b7cbc5bd264966f6a102aefffc299bec4ee7293
MD5 5d50dc76b52532f0acd9ef048914f1b1
BLAKE2b-256 715d6d38ad271ae46588e9978469a1640c30474c50efaf12c4daa832badf8e9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page