90bed0d5f64c2f8b95c16970d3d12efa5e266af0
Feature/update caching * Enable prompt caching for CODE_LAST_CHECK, FILL_BILL_TYPE, DUAL_LOB_CHECK, and GROUPER_BREAKOUT - Add CODE_LAST_CHECK_INSTRUCTION() for service specificity classification - Add FILL_BILL_TYPE_INSTRUCTION() for bill type code determination - Add DUAL_LOB_CHECK_INSTRUCTION() for Medicare/Medicaid classification - Update code_funcs.py to use caching for CODE_LAST_CHECK, FILL_BILL_TYPE, GROUPER_BREAKOUT - Update postprocessing_funcs.py to use caching for DUAL_LOB_CHECK - Add new instructions to get_cacheable_instructions() for cache warming - Add unit tests for new instruction functions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix postprocessing_funcs to remove invalid columns * Merge branch 'main' into feature/lesser-table-caching-refactor-hybrid * Apply black formatting to 11 files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix import paths in testbed files * Merge main into feature/update-caching * Add SPLIT_REIMB_DATES_INSTRUCTION for prompt caching * Merged main into feature/update-caching * Merge remote-tracking branch 'origin/main' into feature/update-caching * Merge branch 'feature/update-caching' of https://bitbucket.org/aarete/doczy.ai into feature/update-caching * Add CODE_* instruction functions for prompt caching * Merged main into feature/update-caching * Merged main into feature/update-caching * Maximize prompt caching by moving static content to instructions - Refactored 12+ prompt functions to move static rules/examples to _INSTRUCTION() - VALIDATE_REIMBURSEMENTS: Moved 45+ lines of validation rules to instruction - DATE_FIX: Moved conversion rules and examples to instruction - EXHIBIT_LEVEL, EXHIBIT_TITLE_MATCH, EXHIBIT_HEADER, EXHIBIT_LINKAGE: Moved rules - FEE_SCHEDULE_BREAKOUT, GROUPER_BREAKOUT: Moved extraction rules - CHECK_PROVIDER_NAME_MATCH: Moved matching rules to instruction - LOB_RELATIONSHIP: Consolidated split instructions - DERIVED_TERM_DATE: Moved calculation logic to instruction - DYNAMIC_PRIMARY: Created separate HEADER and TEXT instructions - Created new REIMB_DATES_ASSIGNMENT_INSTRUCTION with all date rules - Updated get_cacheable_instructions() with new instruction functions - Updated all callers in saas, clover, bcbs_promise pipelines This enables ~90% cost savings via Claude API prompt caching by ensuring static instruction text is cached and only dynamic content varies. * Remove Dynamic Primary Header * Standardize prompt caching across all LLM prompts for ~90% cost savings Move static content to _INSTRUCTION() functions for caching: - METHODOLOGY_BREAKOUT: 8 field definitions with resolved valid_values - FEE_SCHEDULE_BREAKOUT: 3 field definitions - GROUPER_BREAKOUT: 11 field definitions - OUTLIER_BREAKOUT: 8 field definitions - CODE_EXPLICIT: 8 field definitions - EXHIBIT_HEADER: static header markers list - CARVEOUT_CHECK: carveout and special case definitions - SPECIAL_CASE_ASSIGNMENT: task rules and output format Update callers to use cache=True, instruction, and usage_label params. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Apply black formatting to prompt_templates.py * Update unit tests for prompt caching changes - Fix function signatures in tests (METHODOLOGY_BREAKOUT, FEE_SCHEDULE_BREAKOUT, GROUPER_BREAKOUT, CODE_EXPLICIT) - Add tests for CARVEOUT_CHECK and EXHIBIT_HEADER prompts - Add TestInstructionFieldContent class to verify instruction functions contain field definitions - Add tests for CARVEOUT_CHECK_INSTRUCTION and CODE_EXPLICIT_INSTRUCTION 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Refactor instructions to load fields from investment_prompts.json and Constants Address PR review feedback: - Add _get_constants() helper for lazy Constants instantiation - Add _get_fields_text() helper to load fields from investment_prompts.json - METHODOLOGY_BREAKOUT_INSTRUCTION: Load fields via FieldSet - FEE_SCHEDULE_BREAKOUT_INSTRUCTION: Load fields via FieldSet - GROUPER_BREAKOUT_INSTRUCTION: Load fields via FieldSet - OUTLIER_BREAKOUT_INSTRUCTION: Load fields via FieldSet - EXHIBIT_HEADER_INSTRUCTION: Load markers from Constants.EXHIBIT_HEADER_MARKERS - CARVEOUT_CHECK_INSTRUCTION: Load carveouts from Constants.VALID_CARVEOUTS, special cases from investment_prompts.json - CODE_EXPLICIT_INSTRUCTION: Keep hardcoded (no code_explicit field_type in JSON) Update tests to match actual field names from investment_prompts.json. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Merge main into feature/update-caching * Remove deprecated dynamic_primary_header * Update CODE_EXPLICIT_INSTRUCTION to load fields from investment_prompts.json Use field_type=code_primary_breakout to load code fields dynamically. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Merged main into feature/update-caching * Merge main into feature/update-caching * Merge branch 'feature/update-caching' of https://bitbucket.org/aarete/doczy.ai into feature/update-caching Approved-by: Katon Minhas
Field Extraction Pipeline
Contract field extraction using LLMs.
Setup
Install uv (if not already installed)
# Ubuntu/WSL (recommended)
curl -LsSf https://astral.sh/uv/install.sh | sh
source ~/.bashrc # or restart terminal
# macOS
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell - native, not WSL)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Verify installation: uv --version
Install dependencies
uv sync
Running the Code
Use uv run with Python's module flag from the project root:
# Run the default SaaS pipeline
uv run python -m src.pipelines.saas.main
# Run with unified runner (supports client selection)
uv run python -m src.pipelines.runner --client saas --input-dir /path/to/input
# Run with specific client
uv run python -m src.pipelines.runner --client clover --input-dir /path/to/input
Note: Always use uv run to ensure correct virtual environment. Always use -m flag for proper imports.
Development
Before pushing, always run these checks to avoid breaking the CI pipeline:
# Format code
uv run black src/
# Type checking
uv run mypy src/
# Run tests
uv run pytest
All checks must pass before merging to main.
Project Structure
├── src/
│ ├── pipelines/ # Pipeline implementations
│ │ ├── runner.py # Unified CLI entry point with client routing
│ │ ├── saas/ # Default SaaS pipeline
│ │ │ └── main.py # Main entry point for SaaS
│ │ ├── shared/ # Shared pipeline components
│ │ │ ├── preprocessing/ # Document preprocessing
│ │ │ ├── extraction/ # Field extraction logic
│ │ │ └── postprocessing/ # Result postprocessing
│ │ └── clients/ # Client-specific overrides
│ │ └── clover/ # Clover client customizations
│ ├── core/ # Core utilities (registry, fieldset)
│ ├── constants/ # Constants, mappings, and field definitions
│ │ ├── mappings/ # Crosswalk JSON files
│ │ └── lists/ # Lookup lists
│ ├── prompts/ # LLM prompt templates
│ ├── utils/ # Shared utilities (IO, string, logging, etc.)
│ ├── codes/ # Medical code extraction utilities
│ ├── crosswalk/ # Crosswalk mapping logic
│ ├── embeddings/ # Pre-computed embeddings for code matching
│ ├── qc_qa/ # QC/QA validation pipeline
│ ├── parent_child/ # Parent-child relationship mapping
│ ├── document_classification/ # Document type classification (DTC)
│ └── tests/ # Unit tests
├── documentation/ # Project documentation
├── outputs/ # Pipeline output files (gitignored)
├── logs/ # Log files (gitignored)
└── pyproject.toml # Project dependencies (uv/pip)
Branching
Naming Conventions
| Type | Pattern | Use Case | Example |
|---|---|---|---|
| Feature | feature/<ticket>-<description> |
New functionality | feature/PROJ-123-add-export-csv |
| Bugfix | bugfix/<ticket>-<description> |
Bug fixes | bugfix/PROJ-456-fix-null-handling |
| Hotfix | hotfix/<ticket>-<description> |
Urgent production fixes | hotfix/PROJ-789-critical-parse-error |
| Test | test/<description> |
Testing/experimentation | test/lesser-table-caching-refactor |
| Release | release/<version> |
Release preparation | release/v1.2.0 |
Branch Guidelines
- Use lowercase with hyphens (kebab-case) for descriptions
- Include ticket number when applicable (e.g., JIRA, GitHub issue)
- Keep branch names concise but descriptive
- Delete branches after merging
Workflow
- Create branch from
main - Make changes and commit with clear messages
- Run checks before pushing:
uv run black src/ && uv run mypy src/ && uv run pytest - Create PR to
main - Ensure all CI checks pass
- Get code review approval
- Squash and merge
Description
Languages
Python
80.5%
Jupyter Notebook
13%
HCL
3.1%
HTML
1.6%
PLpgSQL
1.5%
Other
0.2%