This repository provides a production-ready, legal reasoning stack centered on a deterministic Native Engine. It includes a native adapter/bridge for legal workloads, a jurisdiction-aware rule builder, authority multipliers, a document-to-graph ingestion CLI, GraphML fixtures, configuration bundles, CI with coverage gating, and comprehensive docs.
What’s new
- Native-only default architecture:
- Deterministic fixed-point engine with threshold semantics and aggregation registry
- Privacy-aware interpretation exports with redaction
- Legal adapter and builder:
- NativeLegalBridge.init() with strict config validation and privacy defaults
- build_rules_for_claim() wires burden-of-proof, statutory styles, and authority multipliers
- Canonical rule builder: build_rules_for_claim_native()
- Authority multipliers (config-driven):
- _compute_authority_multipliers() combines treatment modifiers, recency decay, jurisdiction alignment, and court-level weights
- Ingestion pipeline:
- Document → GraphML via doc_to_graph_auto() or doc_to_graph()
- CLI tool: scripts/ingest/doc_to_graph_cli.py
- CI and quality gates:
- Native unit/integration CI with coverage ≥ 80%: .github/workflows/native-ci.yml
- Legal data compliance:
- Privacy defaults and redaction profiles in exports, data handling guidance in docs/LEGAL_DATA_COMPLIANCE.md
Core implementation files
- Native adapter (default entrypoint): core/adapters/native_bridge.py
- Native legal rules builder (canonical): core/rules_native/native_legal_builder.py
- Engine facade and engine:
- Aggregators and legal operators: ANNOTATION_REGISTRY
- Interpretation export (privacy-aware): Interpretation.export()
- Graph utilities (GraphML + label extraction): extract_specific_labels()
- NLP/doc ingestion:
- Installation (Python 3.10 recommended)
python -m venv .venv
source .venv/bin/activate
# Core deps for native engine path
pip install -r requirements.txtOptional (dev)
- Parity tools and heavy extras are not required; the project operates native-first.
- Add pytest-cov locally if you want coverage reports that match CI:
- pip install pytest-cov
- Configuration (Native)
Primary config files:
- Courts and default clause weights with optional hierarchy/overrides:
- Authority multipliers (recency, jurisdiction alignment, court levels, treatment modifiers):
- Statutory interpretation preferences (textualism, purposivism, lenity):
- Redaction rules for export profiles:
Bridge constructor (strict mode)
- NativeLegalBridge.init() validates all configs and can fail-fast:
from core.adapters.native_bridge import NativeLegalBridge
bridge = NativeLegalBridge(
courts_cfg_path="config/courts.yaml",
precedent_weights_cfg_path="config/precedent_weights.yaml",
statutory_prefs_cfg_path="config/statutory_prefs.yaml",
redaction_cfg_path="config/compliance/redaction_rules.yml",
privacy_defaults=True,
strict_mode=True, # raise on invalid config
)- Quick start (GraphML → reasoning → export)
Using example fixtures in examples/graphs:
- friends_graph.graphml
- group_chat_graph.graphml
from core.adapters.native_bridge import NativeLegalBridge
b = NativeLegalBridge(
courts_cfg_path="config/courts.yaml",
precedent_weights_cfg_path="config/precedent_weights.yaml",
statutory_prefs_cfg_path="config/statutory_prefs.yaml",
redaction_cfg_path="config/compliance/redaction_rules.yml",
privacy_defaults=True,
)
g = b.load_graphml("examples/graphs/friends_graph.graphml", reverse=False)
facts_node, facts_edge, _, _ = b.parse_graph_attributes(static_facts=True)
rules = b.build_rules_for_claim(
claim="breach_of_contract",
jurisdiction="US-CA",
use_conservative=False,
)
interp = b.run_reasoning(
graph=g, facts_node=facts_node, facts_edge=facts_edge, rules=rules, tmax=1
)
# Privacy-aware export (facts only by default profile)
out = b.export_interpretation(interp, profile="default_profile")
print(out["facts"])- Document ingestion CLI (doc → GraphML)
Convert raw text to a GraphML legal graph using NLP (auto) or regex-only (no NLP):
# Auto mode (NER + citations if available)
python -m scripts.ingest.doc_to_graph_cli ./my_case.txt -o examples/graphs/generated_case.graphml --mode auto --jurisdiction US-CA --default-year 2020
# Regex-only mode (always available)
python -m scripts.ingest.doc_to_graph_cli ./my_case.txt -o examples/graphs/generated_case.graphml --mode regexKey ingestion functions:
- Authority multipliers (how it works)
At build-time, if you do not explicitly pass clause weights, the bridge computes multipliers:
- _compute_authority_multipliers():
- Treatment modifier: e.g., followed/criticized/overruled weights
- Recency decay: exponential half-life with a floor
- Jurisdiction alignment: exact/ancestor/sibling/foreign
- Court level weights: e.g., US_SCOTUS=1.0, STATE_TRIAL ~0.78
- Applied to the top-level support rule weights in:
You can still pass explicit weights to override.
- Aggregators and legal styles
Aggregators (registered in ANNOTATION_REGISTRY):
- Burden-of-proof: legal_burden_civil_051(), legal_burden_clear_075(), legal_burden_criminal_090()
- Conservative: legal_conservative_min()
- Precedent-weighted: precedent_weighted()
Interpretation styles (weight tuning):
- textualism, purposivism, lenity via statutory_prefs.yaml
- Privacy and compliance
- Default exports are facts-only; supports/trace require audit_profile.
- Redaction profiles:
- Guidance and controls:
- CI (coverage gating, native-first)
- Native unit/integration CI with coverage ≥ 80%:
- Examples and benchmarks
- End-to-end example: scripts/examples/mini_end_to_end.py
- Benchmarks:
- Troubleshooting and docs
- Troubleshooting: docs/TROUBLESHOOTING.md
- Configuration reference (additions for native engine and redaction): docs/CONFIGURATION_REFERENCE.md
- API guides and examples:
License
- OpenLaw code under repository license terms.