feat(corpus): Stage A — corpus tagging fixes + prevention layer
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 3m8s
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 3m8s
מתקן את הבאג של תיוג שגוי לועדות ערר ומונע חזרתו: **Code changes:** * New MCP tool `internal_decision_upload` (chair_name+district required) — sole supported path for ingesting committee decisions; tags source_kind='internal_committee' automatically. * Citation guard in `precedent_library_upload` rejects citations starting with "ערר" or "בל\"מ" with a directive to use internal_decision_upload. * `practice_area.py` taxonomy unification: PRACTICE_AREAS now accepts both multi-tenant (appeals_committee/national_insurance/labor_law) and domain (rishuy_uvniya/betterment_levy/compensation_197) values. New helper `to_db_practice_area(multi_tenant, subtype) -> domain`. **Agent docs:** * legal-researcher (+5K): upload-tool decision flowchart, code samples per source_kind, district enum (ירושלים/מרכז/תל אביב/צפון/דרום/חיפה/ארצי) * legal-ceo, legal-analyst, legal-writer, legal-qa, HEARTBEAT — taxonomy awareness + source_kind-aware citation patterns + research_complete as valid status. * Fixed two pre-existing wrong practice_area values in examples (histael_hashbacha→betterment_levy, pitsuim_197→compensation_197). Closes TaskMaster #30(parts), #38(parts), #39 (root cause). DB-side backfill + CHECK constraints applied directly via psql: * 11 cases.practice_area corrected (1xxx→rishuy, 8xxx→betterment) * 6 case_law records reclassified external_upload→internal_committee with inferred district * 6 chair_name backfilled from full_text (5 שרית אריאלי + 1 דפנה תמיר) * 88 new halachot extracted for newly-uploaded precedents (אנטרים + ירושלים שקופה 1112/22 + אגא וכט) * CHECK constraints: cases.practice_area enum, case_law internal⇒district Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,14 +2,34 @@
|
||||
|
||||
Two orthogonal axes used to separate legal domains across the system:
|
||||
|
||||
practice_area — top-level domain (multi-tenant axis). Examples:
|
||||
appeals_committee, national_insurance, labor_law.
|
||||
appeal_subtype — refines within a domain. For appeals_committee:
|
||||
building_permit (1xxx), betterment_levy (8xxx),
|
||||
compensation_197 (9xxx), unknown.
|
||||
practice_area — top-level domain. **Two taxonomies coexist** (see below).
|
||||
appeal_subtype — refines within a domain.
|
||||
|
||||
Both columns are denormalized into documents/chunks/decisions/style_corpus
|
||||
so vector searches can filter cheaply.
|
||||
⚠️ TWO TAXONOMIES — DO NOT CONFUSE
|
||||
==================================
|
||||
|
||||
A. **Multi-tenant axis** (legacy, used in routing logic):
|
||||
- ``appeals_committee`` — the legal-ai instance for Daphna's committee
|
||||
- ``national_insurance`` — future / hypothetical other tenants
|
||||
- ``labor_law`` — future
|
||||
When this axis is used, ``appeal_subtype`` carries the actual domain:
|
||||
``building_permit`` (1xxx), ``betterment_levy`` (8xxx),
|
||||
``compensation_197`` (9xxx).
|
||||
|
||||
B. **Domain axis** (DB columns ``case_law.practice_area``,
|
||||
``cases.practice_area`` — what tests, validators, and CHECK constraints
|
||||
actually use):
|
||||
- ``rishuy_uvniya`` — רישוי ובנייה (1xxx)
|
||||
- ``betterment_levy`` — היטל השבחה (8xxx)
|
||||
- ``compensation_197`` — פיצויים סעיף 197 (9xxx)
|
||||
|
||||
Use ``to_db_practice_area(multi_tenant_pa, appeal_subtype)`` to convert
|
||||
from axis A to axis B before writing to the DB.
|
||||
|
||||
Background: TaskMaster #30 (sub-bug ב) — many ``case_law`` rows stored
|
||||
``appeals_committee`` (axis A) where they should have stored a domain
|
||||
value (axis B). The migration backfill plus CHECK constraints close the
|
||||
gap, and this module now validates **both** namespaces.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -18,12 +38,23 @@ import re
|
||||
|
||||
# ── Enums ──────────────────────────────────────────────────────────
|
||||
|
||||
PRACTICE_AREAS: set[str] = {
|
||||
# Multi-tenant axis (legacy)
|
||||
MULTI_TENANT_PRACTICE_AREAS: set[str] = {
|
||||
"appeals_committee",
|
||||
"national_insurance",
|
||||
"labor_law",
|
||||
}
|
||||
|
||||
# Domain axis (matches DB constraints on case_law/cases)
|
||||
DOMAIN_PRACTICE_AREAS: set[str] = {
|
||||
"rishuy_uvniya",
|
||||
"betterment_levy",
|
||||
"compensation_197",
|
||||
}
|
||||
|
||||
# Union — what ``validate()`` accepts for backward-compat
|
||||
PRACTICE_AREAS: set[str] = MULTI_TENANT_PRACTICE_AREAS | DOMAIN_PRACTICE_AREAS
|
||||
|
||||
APPEALS_COMMITTEE_SUBTYPES: set[str] = {
|
||||
"building_permit",
|
||||
"betterment_levy",
|
||||
@@ -38,8 +69,42 @@ SUBTYPES_BY_AREA: dict[str, set[str]] = {
|
||||
"appeals_committee": APPEALS_COMMITTEE_SUBTYPES,
|
||||
"national_insurance": {"unknown"},
|
||||
"labor_law": {"unknown"},
|
||||
# Domain values — subtype is implicit in the value itself
|
||||
"rishuy_uvniya": {"building_permit", "unknown"},
|
||||
"betterment_levy": {"betterment_levy", "unknown"},
|
||||
"compensation_197": {"compensation_197", "unknown"},
|
||||
}
|
||||
|
||||
# Mapping: (multi_tenant_pa, appeal_subtype) → domain_pa
|
||||
_SUBTYPE_TO_DOMAIN: dict[str, str] = {
|
||||
"building_permit": "rishuy_uvniya",
|
||||
"betterment_levy": "betterment_levy",
|
||||
"compensation_197": "compensation_197",
|
||||
}
|
||||
|
||||
|
||||
def to_db_practice_area(practice_area: str, appeal_subtype: str = "") -> str:
|
||||
"""Convert a multi-tenant practice_area + appeal_subtype to the
|
||||
domain value stored in DB columns (case_law/cases).
|
||||
|
||||
Returns ``""`` when the input cannot be mapped — callers should
|
||||
handle this rather than letting ``""`` propagate silently to the DB.
|
||||
|
||||
Examples:
|
||||
>>> to_db_practice_area("appeals_committee", "building_permit")
|
||||
'rishuy_uvniya'
|
||||
>>> to_db_practice_area("rishuy_uvniya")
|
||||
'rishuy_uvniya'
|
||||
>>> to_db_practice_area("appeals_committee")
|
||||
''
|
||||
"""
|
||||
pa = (practice_area or "").strip()
|
||||
if pa in DOMAIN_PRACTICE_AREAS:
|
||||
return pa
|
||||
if pa == "appeals_committee":
|
||||
return _SUBTYPE_TO_DOMAIN.get((appeal_subtype or "").strip(), "")
|
||||
return ""
|
||||
|
||||
|
||||
# ── Derivation ─────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user