Step 3: config, schemas, and prompts spec — all validated
Browse filesAdds specs/01_config_and_schemas.md documenting the already-implemented stubs.
All Pydantic models validate correctly; config constants confirmed correct.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- specs/01_config_and_schemas.md +145 -0
specs/01_config_and_schemas.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Spec 01 — Config, Schemas, and Prompts
|
| 2 |
+
|
| 3 |
+
**Step:** 3 of 15
|
| 4 |
+
**Time budget:** ~25 min
|
| 5 |
+
**Checkpoint:** `python -c "from core import config, schemas, prompts"` runs without error. All Pydantic models validate sample JSON correctly.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Goal
|
| 10 |
+
|
| 11 |
+
Finalize `core/config.py`, `core/schemas.py`, and `core/prompts.py` with full working implementations (the skeleton stubs already have the correct content — this step validates and documents them).
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
## `core/config.py`
|
| 16 |
+
|
| 17 |
+
Loads environment variables. All values are module-level constants.
|
| 18 |
+
|
| 19 |
+
| Constant | Type | Value / Source |
|
| 20 |
+
|---|---|---|
|
| 21 |
+
| `DEEPSEEK_API_KEY` | `str | None` | `os.getenv("DEEPSEEK_API_KEY")` |
|
| 22 |
+
| `DEEPSEEK_BASE_URL` | `str` | `"https://api.deepseek.com/v1"` |
|
| 23 |
+
| `MODEL_NAME` | `str` | `"deepseek-chat"` |
|
| 24 |
+
| `MODEL_VERSION` | `str` | `f"{MODEL_NAME}@2026-05-07"` |
|
| 25 |
+
| `CONFIDENCE_HIGH` | `float` | `0.80` |
|
| 26 |
+
| `CONFIDENCE_REVIEW` | `float` | `0.55` |
|
| 27 |
+
| `OCR_TESSERACT_MIN_CONF` | `float` | `0.65` |
|
| 28 |
+
| `BASE_DIR` | `Path` | parent of `core/` |
|
| 29 |
+
| `DATA_DIR` | `Path` | `BASE_DIR / "data"` |
|
| 30 |
+
| `CHROMA_DIR` | `str` | `str(BASE_DIR / ".chroma")` |
|
| 31 |
+
| `AUDIT_DB` | `str` | `str(BASE_DIR / "audit.db")` |
|
| 32 |
+
| `PRECOMPUTED_DIR` | `Path` | `DATA_DIR / "precomputed"` |
|
| 33 |
+
| `OCR_CACHE_DIR` | `Path` | `BASE_DIR / ".ocr_cache"` |
|
| 34 |
+
|
| 35 |
+
`load_dotenv()` is called at module level so `.env` is sourced before `os.getenv`.
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## `core/schemas.py`
|
| 40 |
+
|
| 41 |
+
Pydantic v2 models. All fields have type annotations. Use `from __future__ import annotations`.
|
| 42 |
+
|
| 43 |
+
### `Rule`
|
| 44 |
+
```python
|
| 45 |
+
class Rule(BaseModel):
|
| 46 |
+
type: Literal["numeric_threshold", "count_threshold", "certification_present", "document_present"]
|
| 47 |
+
field: str
|
| 48 |
+
operator: Literal[">=", "<=", "==", "exists"]
|
| 49 |
+
value: float | int | None = None
|
| 50 |
+
unit: str | None = None
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
### `Criterion`
|
| 54 |
+
```python
|
| 55 |
+
class Criterion(BaseModel):
|
| 56 |
+
id: str
|
| 57 |
+
title: str
|
| 58 |
+
category: Literal["financial", "technical", "compliance"]
|
| 59 |
+
mandatory: bool
|
| 60 |
+
description: str
|
| 61 |
+
rule: Rule
|
| 62 |
+
query_hints: list[str]
|
| 63 |
+
source_page: int
|
| 64 |
+
source_clause: str
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
### `Evidence`
|
| 68 |
+
```python
|
| 69 |
+
class Evidence(BaseModel):
|
| 70 |
+
bidder_id: str
|
| 71 |
+
doc_name: str
|
| 72 |
+
page: int
|
| 73 |
+
text: str
|
| 74 |
+
source_type: Literal["text_pdf", "tesseract", "vision_llm"]
|
| 75 |
+
ocr_confidence: float | None = None
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### `Source`
|
| 79 |
+
```python
|
| 80 |
+
class Source(BaseModel):
|
| 81 |
+
doc_name: str
|
| 82 |
+
page: int
|
| 83 |
+
snippet: str
|
| 84 |
+
source_type: Literal["text_pdf", "tesseract", "vision_llm"]
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### `Verdict`
|
| 88 |
+
```python
|
| 89 |
+
class Verdict(BaseModel):
|
| 90 |
+
verdict_id: str = Field(default_factory=lambda: f"V-{uuid.uuid4().hex[:8]}")
|
| 91 |
+
bidder_id: str
|
| 92 |
+
criterion_id: str
|
| 93 |
+
verdict: Literal["eligible", "not_eligible", "needs_review"]
|
| 94 |
+
extracted_value: str | None = None
|
| 95 |
+
normalized_value: float | int | None = None
|
| 96 |
+
source: Source | None = None
|
| 97 |
+
llm_confidence: float = 0.0
|
| 98 |
+
ocr_confidence: float | None = None
|
| 99 |
+
combined_confidence: float = 0.0
|
| 100 |
+
reason: str = ""
|
| 101 |
+
model_version: str = ""
|
| 102 |
+
timestamp: str = ""
|
| 103 |
+
review_status: Literal["pending", "approved", "edited", "rejected"] = "pending"
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### `AuditEntry`
|
| 107 |
+
```python
|
| 108 |
+
class AuditEntry(BaseModel):
|
| 109 |
+
id: int | None = None
|
| 110 |
+
ts: str
|
| 111 |
+
action: str
|
| 112 |
+
actor: str
|
| 113 |
+
model_version: str | None = None
|
| 114 |
+
bidder_id: str | None = None
|
| 115 |
+
criterion_id: str | None = None
|
| 116 |
+
payload_json: str | None = None
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
---
|
| 120 |
+
|
| 121 |
+
## `core/prompts.py`
|
| 122 |
+
|
| 123 |
+
Three string constants already defined in the skeleton — no changes needed.
|
| 124 |
+
|
| 125 |
+
- `EXTRACT_CRITERIA_PROMPT_SYSTEM`
|
| 126 |
+
- `EVALUATE_CRITERION_PROMPT_SYSTEM`
|
| 127 |
+
- `VISION_OCR_PROMPT_SYSTEM`
|
| 128 |
+
- `VISION_OCR_USER`
|
| 129 |
+
|
| 130 |
+
---
|
| 131 |
+
|
| 132 |
+
## Acceptance Criteria
|
| 133 |
+
|
| 134 |
+
1. `python -c "from core import config, schemas, prompts"` exits 0.
|
| 135 |
+
2. `python -c "from core.schemas import Criterion, Verdict, Evidence, AuditEntry; print('OK')"` prints OK.
|
| 136 |
+
3. Sample Criterion JSON validates without error:
|
| 137 |
+
```python
|
| 138 |
+
from core.schemas import Criterion
|
| 139 |
+
c = Criterion(**{"id":"C1","title":"Turnover","category":"financial",
|
| 140 |
+
"mandatory":True,"description":"INR 5Cr","rule":{"type":"numeric_threshold",
|
| 141 |
+
"field":"turnover","operator":">=","value":50000000,"unit":"INR"},
|
| 142 |
+
"query_hints":["turnover"],"source_page":3,"source_clause":"3.2(a)"})
|
| 143 |
+
assert c.mandatory is True
|
| 144 |
+
```
|
| 145 |
+
4. `config.MODEL_VERSION` contains `"deepseek-chat@2026-05-07"`.
|