A comprehensive Python library for parsing and analyzing case file documents using Large Language Models (LLMs). The library supports multiple parsing strategies, from structured JSON extraction to iterative knowledge graph construction, enabling flexible analysis of unstructured case file data.
src/casefile_parser/: Contains source files for building thecasefile_parserpackage, which is used by the Lambdas and Jupyter notebooks.nibrs/specs/: Ontology specifications and a guide for developers can be found here.nibrs/sample_reports/: Variations of the mark43 nibrs_AllFields_Sample.xml sample report in XML, JSON, and OpenCypher edge list formats can be found here.nibrs/specs/data_element_maps/: Data element code taxonomic maps sourced from the Washington Association of Sheriffs and Police Chiefs can be found here.
The NIBRS "Property" data element taxonomy in their dev guide is a bit restrictive and makes it difficult to place weapons, clothing, damaged/stolen goods, and other major categories of things within the same embedding space. This has given me endless headaches for the last year. Thankfully, Google's Product Taxonomy is great for this. Embedding an object within the shared feature space is then just an issue of locating the most relevant branch of the taxonomy.
As such, the paths to leaves of version 2021-09-21 of the taxonomy have been one-hot encoded and stored in src/casefile_parser/taxonomies/OBJECTS.tsv
- Multi-Provider LLM Support: Seamlessly integrates with AWS Bedrock, Anthropic Claude, OpenAI GPT, and Cohere (I've only tested the most recent version with Claude)
- Dual Parsing Strategies: JSON-based structured extraction and graph-based iterative enrichment
- Schema-Driven Extraction: Configurable schemas ensure consistent and validated output
- Iterative Enrichment: LangGraph-powered workflows for progressive knowledge discovery
- Enterprise-Grade: Comprehensive error handling, logging, and monitoring
- Batch Processing: Efficient processing of large document collections
- Type Safety: Full type hints and Pydantic validation throughout
For detailed documentation, API reference, and advanced usage examples, see:
# Install package in development mode with anthropic support
pip install -e git+https://github.com/IsaacFigNewton/case-file-analysis.git[anthropic]from casefile_parser.parsers.json_parser import JSONParser
# Initialize parser
parser = JSONParser()
# Parse document
text = "Officer Smith responded to a robbery at 123 Main St..."
result = parser.call_llm(text)
# Access results
print(f"Case ID: {result.incident_case_id}")
print(f"Primary Offense: {result.primary_offense_type}")from casefile_parser.parsers.triplet_parser import TripletParser
# Initialize with schema
parser = TripletParser(schema_path="schemas/CaseFileSchema.csv")
# Parse and build graph
graph = parser.parse(text)
# Explore graph
for node in graph.data['nodes']:
print(f"Entity: {node.id} (Type: {node.type})")Create a .env file in your project root based on .env.example:
# API Keys
ANTHROPIC_API_KEY=your_key_here
OPENAI_API_KEY=your_key_here
COHERE_API_KEY=your_key_here
# AWS Configuration
AWS_PROFILE=default
AWS_REGION=us-east-1
# Logging
LOG_LEVEL=INFO
LOG_FORMAT=jsonThe library follows a modular architecture with clear separation of concerns:
- Core Components: LLMProviderManager, CaseFileManager, TextPreprocessor
- Parser Implementations: JSONParser for structured data, TripletParser for graph construction
- Schema Management: Pydantic models for validation and type safety
- Interfaces: Abstract base classes ensuring consistent APIs
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html --cov-report=term-missing
# Run specific categories
pytest -m unit # Unit tests only
pytest -m integration # Integration tests only
pytest -m "not slow" # Skip slow testsThe comprehensive test suite covers:
- Parser Tests: JSON and triplet parser functionality
- Postprocessing Tests: Entity extraction, graph transformation, schema validation
- Core Tests: File management, LLM provider integration, logging
- Integration Tests: End-to-end pipeline testing
pip install pytest pytest-covsrc/casefile_parser/
├── parsers/ # Parser implementations
│ ├── json_parser/ # Structured JSON extraction
│ └── triplet_parser/ # Knowledge graph construction
├── interfaces/ # Abstract base classes
├── schemas/ # Data models and validation
├── preprocessing/ # Text cleaning utilities
├── postprocessing/ # Graph processing utilities
└── utils/ # Utility modules
tests/ # Comprehensive test suite
├── parsers/ # Parser-specific tests
├── postprocessing/ # Postprocessing tests
└── conftest.py # Shared fixtures and configuration
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Write tests for your changes
- Ensure all tests pass (
pytest) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .[dev]
# Install pre-commit hooks
pre-commit installThis project is licensed under the Apache 2.0 License - see the LICENSE file for details.
For questions, issues, or contributions, please:
- Open an issue on GitHub
- Contact the maintainers (Isaac)
- Join our community discussions
