File size: 24,820 Bytes
c5e2a8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
"""

Bias Detection and Outcome Prediction Engine using InLegalBERT

================================================================



This module provides:

1. Document/Text bias detection (gender, region, caste, etc.)

2. RAG output bias detection (tone, interpretive bias)

3. Systemic/Statistical bias analysis

4. Legal outcome prediction with confidence scores



Model: InLegalBERT (Hugging Face pretrained for Indian legal cases)

"""

import torch
import numpy as np
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModel
from typing import Dict, List, Any, Optional, Union
import re
from collections import Counter
import json
from datetime import datetime
import warnings
warnings.filterwarnings('ignore')

# ============================================================================
# MODEL INITIALIZATION
# ============================================================================

class InLegalBERTEngine:
    """

    Main engine for bias detection and outcome prediction using InLegalBERT

    """
    
    def __init__(self, model_name: str = "law-ai/InLegalBERT"):
        """

        Initialize the InLegalBERT model and tokenizer

        

        Args:

            model_name: HuggingFace model identifier (use your fine-tuned model path)

        """
        print(f"Loading InLegalBERT model: {model_name}")
        
        # Load tokenizer and base model for embeddings
        # TODO: Replace "law-ai/InLegalBERT" with your fine-tuned model path
        # Example: "your-username/inlegalbert-bias-finetuned"
        self.tokenizer = AutoTokenizer.from_pretrained(model_name)
        self.base_model = AutoModel.from_pretrained(model_name)
        
        # Set device
        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        self.base_model.to(self.device)
        self.base_model.eval()
        
        # Bias detection keywords (Indian legal context)
        self.bias_keywords = {
            'gender': [
                'woman', 'women', 'girl', 'female', 'lady', 'wife', 'mother',
                'man', 'men', 'boy', 'male', 'husband', 'father', 'manhood', 'womanhood'
            ],
            'caste': [
                'scheduled caste', 'sc', 'st', 'scheduled tribe', 'obc', 'backward class',
                'dalit', 'brahmin', 'upper caste', 'lower caste', 'caste', 'jati'
            ],
            'religion': [
                'hindu', 'muslim', 'christian', 'sikh', 'buddhist', 'jain',
                'religious', 'communal', 'minority', 'majority community'
            ],
            'region': [
                'north', 'south', 'east', 'west', 'rural', 'urban', 'tribal',
                'metropolitan', 'village', 'city', 'state', 'region'
            ],
            'socioeconomic': [
                'poor', 'rich', 'wealthy', 'poverty', 'income', 'economically',
                'below poverty line', 'bpl', 'weaker section', 'privileged'
            ],
            'age': [
                'minor', 'juvenile', 'child', 'elderly', 'senior citizen', 'youth',
                'old', 'young', 'aged'
            ]
        }
        
        print(f"Model loaded successfully on {self.device}")
    
    # ========================================================================
    # UTILITY FUNCTIONS
    # ========================================================================
    
    def get_embeddings(self, text: str) -> torch.Tensor:
        """

        Get BERT embeddings for input text

        

        Args:

            text: Input text string

            

        Returns:

            torch.Tensor: Embedding vector

        """
        # Tokenize
        inputs = self.tokenizer(
            text,
            return_tensors="pt",
            truncation=True,
            max_length=512,
            padding=True
        ).to(self.device)
        
        # Get embeddings
        with torch.no_grad():
            outputs = self.base_model(**inputs)
            # Use CLS token embedding (first token)
            embeddings = outputs.last_hidden_state[:, 0, :]
        
        return embeddings
    
    def compute_bias_score(self, text: str, bias_type: str) -> float:
        """

        Compute bias score for a specific bias type using keyword frequency

        and contextual analysis

        

        Args:

            text: Input text

            bias_type: Type of bias (gender, caste, etc.)

            

        Returns:

            float: Bias score between 0 and 1

        """
        text_lower = text.lower()
        keywords = self.bias_keywords.get(bias_type, [])
        
        # Count keyword occurrences
        keyword_count = sum(text_lower.count(keyword) for keyword in keywords)
        
        # Normalize by text length (words)
        word_count = len(text.split())
        if word_count == 0:
            return 0.0
        
        # Calculate frequency-based score
        frequency_score = min(keyword_count / word_count * 10, 1.0)
        
        # Get contextual score using embeddings (simplified)
        # In production, use a fine-tuned classifier
        contextual_score = frequency_score * 0.8  # Simplified
        
        return round(contextual_score, 3)
    
    # ========================================================================
    # 1. DOCUMENT/TEXT BIAS DETECTION
    # ========================================================================
    
    def detect_document_bias(self, text: str, threshold: float = 0.15) -> Dict[str, Any]:
        """

        Detect various biases in legal documents/FIRs/judgments

        

        Args:

            text: Legal document text

            threshold: Minimum score to flag a bias (default 0.15)

            

        Returns:

            Dict containing bias flags and detailed scores

        """
        bias_scores = {}
        bias_flags = []
        
        # Analyze each bias type
        for bias_type in self.bias_keywords.keys():
            score = self.compute_bias_score(text, bias_type)
            bias_scores[bias_type] = score
            
            if score >= threshold:
                bias_flags.append(bias_type)
        
        # Determine severity levels
        bias_details = []
        for bias_type, score in bias_scores.items():
            if score >= threshold:
                severity = "high" if score >= 0.4 else "medium" if score >= 0.25 else "low"
                bias_details.append({
                    "type": bias_type,
                    "severity": severity,
                    "score": score,
                    "description": f"{bias_type.capitalize()} bias detected based on keyword analysis and context"
                })
        
        return {
            "biasFlags_text": bias_flags,
            "bias_scores": bias_scores,
            "bias_details": bias_details,
            "overall_bias_score": round(np.mean(list(bias_scores.values())), 3),
            "analysis_timestamp": datetime.now().isoformat()
        }
    
    # ========================================================================
    # 2. RAG OUTPUT BIAS DETECTION
    # ========================================================================
    
    def detect_rag_output_bias(self, 

                               rag_summary: str, 

                               source_documents: List[str]) -> Dict[str, Any]:
        """

        Detect bias in AI-generated RAG summaries/reasoning

        

        Args:

            rag_summary: AI-generated summary or reasoning

            source_documents: Original source documents used for RAG

            

        Returns:

            Dict containing RAG-specific bias flags

        """
        bias_flags = []
        bias_details = []
        
        # Get embeddings
        summary_emb = self.get_embeddings(rag_summary)
        source_embs = [self.get_embeddings(doc) for doc in source_documents[:5]]  # Limit to 5
        
        # 1. TONE BIAS - Check if summary tone differs from sources
        if source_embs:
            avg_source_emb = torch.mean(torch.stack(source_embs), dim=0)
            # Cosine similarity
            similarity = torch.nn.functional.cosine_similarity(summary_emb, avg_source_emb)
            
            if similarity < 0.7:  # Low similarity indicates tone shift
                bias_flags.append("tone_bias")
                bias_details.append({
                    "type": "tone_bias",
                    "severity": "medium",
                    "score": round(1 - similarity.item(), 3),
                    "description": "AI summary tone differs significantly from source documents"
                })
        
        # 2. INTERPRETIVE BIAS - Check for subjective language
        subjective_words = [
            'clearly', 'obviously', 'undoubtedly', 'certainly', 'definitely',
            'surely', 'apparently', 'seemingly', 'arguably', 'presumably'
        ]
        summary_lower = rag_summary.lower()
        subjective_count = sum(summary_lower.count(word) for word in subjective_words)
        
        if subjective_count > 2:
            bias_flags.append("interpretive_bias")
            bias_details.append({
                "type": "interpretive_bias",
                "severity": "medium" if subjective_count > 4 else "low",
                "score": round(min(subjective_count / 10, 1.0), 3),
                "description": f"Summary contains {subjective_count} subjective/interpretive terms"
            })
        
        # 3. SELECTIVITY BIAS - Check if summary over-represents certain aspects
        # Count mentions of different legal aspects
        aspects = {
            'procedural': ['procedure', 'process', 'filing', 'hearing', 'appeal'],
            'substantive': ['law', 'statute', 'provision', 'section', 'act'],
            'factual': ['fact', 'evidence', 'witness', 'testimony', 'statement']
        }
        
        aspect_counts = {k: sum(summary_lower.count(w) for w in v) for k, v in aspects.items()}
        max_count = max(aspect_counts.values()) if aspect_counts.values() else 1
        
        if max_count > 5 and any(count < max_count * 0.3 for count in aspect_counts.values()):
            bias_flags.append("selectivity_bias")
            bias_details.append({
                "type": "selectivity_bias",
                "severity": "low",
                "score": 0.4,
                "description": "Summary may over-emphasize certain legal aspects"
            })
        
        return {
            "biasFlags_output": bias_flags,
            "bias_details": bias_details,
            "analysis_timestamp": datetime.now().isoformat()
        }
    
    # ========================================================================
    # 3. SYSTEMIC/STATISTICAL BIAS DETECTION
    # ========================================================================
    
    def detect_systemic_bias(self, 

                            historical_cases: List[Dict[str, Any]]) -> Dict[str, Any]:
        """

        Analyze systemic and statistical biases from historical case data

        

        Args:

            historical_cases: List of case dictionaries with keys:

                - outcome: str (e.g., "conviction", "acquittal")

                - gender: str (optional)

                - region: str (optional)

                - caste: str (optional)

                - case_type: str

                - year: int

                

        Returns:

            Dict containing systemic bias metrics and dashboard data

        """
        if not historical_cases:
            return {"error": "No historical cases provided"}
        
        # Initialize analytics
        outcome_by_gender = {}
        outcome_by_region = {}
        outcome_by_caste = {}
        outcome_by_year = {}
        
        # Process cases
        for case in historical_cases:
            outcome = case.get('outcome', 'unknown')
            
            # Gender analysis
            if 'gender' in case:
                gender = case['gender']
                if gender not in outcome_by_gender:
                    outcome_by_gender[gender] = []
                outcome_by_gender[gender].append(outcome)
            
            # Region analysis
            if 'region' in case:
                region = case['region']
                if region not in outcome_by_region:
                    outcome_by_region[region] = []
                outcome_by_region[region].append(outcome)
            
            # Caste analysis
            if 'caste' in case:
                caste = case['caste']
                if caste not in outcome_by_caste:
                    outcome_by_caste[caste] = []
                outcome_by_caste[caste].append(outcome)
            
            # Temporal analysis
            if 'year' in case:
                year = case['year']
                if year not in outcome_by_year:
                    outcome_by_year[year] = []
                outcome_by_year[year].append(outcome)
        
        # Calculate disparity metrics
        def calculate_disparity(outcome_dict: Dict) -> Dict:
            """Calculate outcome disparities"""
            disparity_data = {}
            for category, outcomes in outcome_dict.items():
                total = len(outcomes)
                if total > 0:
                    conviction_rate = outcomes.count('conviction') / total
                    disparity_data[category] = {
                        'total_cases': total,
                        'conviction_rate': round(conviction_rate, 3),
                        'acquittal_rate': round(outcomes.count('acquittal') / total, 3)
                    }
            return disparity_data
        
        gender_disparity = calculate_disparity(outcome_by_gender)
        region_disparity = calculate_disparity(outcome_by_region)
        caste_disparity = calculate_disparity(outcome_by_caste)
        
        # Detect significant disparities
        bias_flags = []
        
        if gender_disparity:
            rates = [d['conviction_rate'] for d in gender_disparity.values()]
            if max(rates) - min(rates) > 0.15:
                bias_flags.append("gender_disparity")
        
        if region_disparity:
            rates = [d['conviction_rate'] for d in region_disparity.values()]
            if max(rates) - min(rates) > 0.15:
                bias_flags.append("regional_disparity")
        
        if caste_disparity:
            rates = [d['conviction_rate'] for d in caste_disparity.values()]
            if max(rates) - min(rates) > 0.15:
                bias_flags.append("caste_disparity")
        
        # Generate dashboard-ready data
        dashboard_data = {
            "summary_metrics": {
                "total_cases_analyzed": len(historical_cases),
                "overall_conviction_rate": round(
                    sum(1 for c in historical_cases if c.get('outcome') == 'conviction') / len(historical_cases),
                    3
                ),
                "bias_flags_detected": len(bias_flags)
            },
            "gender_analysis": {
                "disparity_data": gender_disparity,
                "chart_data": [
                    {"category": k, "conviction_rate": v['conviction_rate']} 
                    for k, v in gender_disparity.items()
                ]
            },
            "regional_analysis": {
                "disparity_data": region_disparity,
                "chart_data": [
                    {"category": k, "conviction_rate": v['conviction_rate']} 
                    for k, v in region_disparity.items()
                ]
            },
            "caste_analysis": {
                "disparity_data": caste_disparity,
                "chart_data": [
                    {"category": k, "conviction_rate": v['conviction_rate']} 
                    for k, v in caste_disparity.items()
                ]
            },
            "temporal_trends": {
                "by_year": {
                    year: {
                        'total': len(outcomes),
                        'conviction_rate': round(outcomes.count('conviction') / len(outcomes), 3)
                    }
                    for year, outcomes in outcome_by_year.items()
                }
            }
        }
        
        return {
            "systemic_bias_flags": bias_flags,
            "biasDashboardData": dashboard_data,
            "analysis_timestamp": datetime.now().isoformat()
        }
    
    # ========================================================================
    # 4. OUTCOME PREDICTION
    # ========================================================================
    
    def predict_outcome(self, 

                       case_text: str,

                       case_metadata: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
        """

        Predict legal case outcome using InLegalBERT embeddings and heuristics

        

        Args:

            case_text: Full case text (FIR, facts, arguments, etc.)

            case_metadata: Optional metadata (case_type, jurisdiction, etc.)

            

        Returns:

            Dict containing prediction, confidence, and justification

        """
        # Get text embeddings
        embeddings = self.get_embeddings(case_text)
        
        # Keyword-based prediction (simplified - in production use fine-tuned classifier)
        conviction_keywords = [
            'guilty', 'convicted', 'evidence proves', 'beyond reasonable doubt',
            'establish', 'proven', 'corroborated', 'substantiated'
        ]
        acquittal_keywords = [
            'not guilty', 'acquitted', 'benefit of doubt', 'insufficient evidence',
            'failed to prove', 'contradictory', 'unreliable', 'doubt'
        ]
        
        text_lower = case_text.lower()
        conviction_score = sum(text_lower.count(kw) for kw in conviction_keywords)
        acquittal_score = sum(text_lower.count(kw) for kw in acquittal_keywords)
        
        # Calculate prediction
        total_score = conviction_score + acquittal_score
        if total_score == 0:
            # No strong indicators, use neutral prediction
            predicted_outcome = "uncertain"
            confidence_score = 0.5
            justification = "Insufficient textual indicators for confident prediction"
        else:
            conviction_prob = conviction_score / total_score
            
            if conviction_prob > 0.6:
                predicted_outcome = "conviction"
                confidence_score = round(conviction_prob, 3)
                justification = f"Text analysis shows {conviction_score} conviction indicators vs {acquittal_score} acquittal indicators"
            elif conviction_prob < 0.4:
                predicted_outcome = "acquittal"
                confidence_score = round(1 - conviction_prob, 3)
                justification = f"Text analysis shows {acquittal_score} acquittal indicators vs {conviction_score} conviction indicators"
            else:
                predicted_outcome = "uncertain"
                confidence_score = 0.5
                justification = "Mixed indicators suggest uncertain outcome"
        
        # Adjust for metadata if provided
        if case_metadata:
            case_type = case_metadata.get('case_type', '').lower()
            
            # Example adjustments (customize based on domain knowledge)
            if 'bail' in case_type:
                if predicted_outcome == "conviction":
                    predicted_outcome = "bail_denied"
                    justification += "; Bail application context considered"
                elif predicted_outcome == "acquittal":
                    predicted_outcome = "bail_granted"
                    justification += "; Bail application context considered"
        
        # Confidence level categorization
        if confidence_score >= 0.75:
            confidence_level = "high"
        elif confidence_score >= 0.5:
            confidence_level = "medium"
        else:
            confidence_level = "low"
        
        return {
            "predictedOutcome": predicted_outcome,
            "confidenceScore": confidence_score,
            "confidenceLevel": confidence_level,
            "justification": justification,
            "embedding_norm": float(torch.norm(embeddings).item()),
            "analysis_timestamp": datetime.now().isoformat()
        }

# ============================================================================
# API INTERFACE FUNCTIONS
# ============================================================================

# Global model instance (loaded once)
_model_instance = None

def get_model() -> InLegalBERTEngine:
    """Get or create model instance (singleton pattern)"""
    global _model_instance
    if _model_instance is None:
        _model_instance = InLegalBERTEngine()
    return _model_instance


def analyze_legal_case(

    case_text: str,

    rag_summary: Optional[str] = None,

    source_documents: Optional[List[str]] = None,

    historical_cases: Optional[List[Dict]] = None,

    case_metadata: Optional[Dict] = None

) -> Dict[str, Any]:
    """

    Main API function for comprehensive legal case analysis

    

    Args:

        case_text: Legal document/FIR/judgment text

        rag_summary: AI-generated summary (for RAG bias detection)

        source_documents: Source docs used for RAG (for RAG bias detection)

        historical_cases: Historical case data (for systemic bias analysis)

        case_metadata: Case metadata for outcome prediction

        

    Returns:

        JSON-serializable dict with all analysis results

    """
    model = get_model()
    
    results = {
        "status": "success",
        "analysis_id": f"analysis_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
        "timestamp": datetime.now().isoformat()
    }
    
    # 1. Document bias detection
    if case_text:
        results["document_bias"] = model.detect_document_bias(case_text)
    
    # 2. RAG output bias detection
    if rag_summary and source_documents:
        results["rag_bias"] = model.detect_rag_output_bias(rag_summary, source_documents)
    
    # 3. Systemic bias analysis
    if historical_cases:
        results["systemic_bias"] = model.detect_systemic_bias(historical_cases)
    
    # 4. Outcome prediction
    if case_text:
        results["outcome_prediction"] = model.predict_outcome(case_text, case_metadata)
    
    return results


# ============================================================================
# EXAMPLE USAGE
# ============================================================================

if __name__ == "__main__":
    # Example legal case text
    sample_case = """

    The accused, a 35-year-old woman from rural Maharashtra, was charged under 

    Section 302 IPC for alleged murder. The prosecution's case relies heavily on 

    circumstantial evidence. The witness testimonies are contradictory, and the 

    forensic evidence is inconclusive. The accused belongs to a scheduled caste 

    community. The defense argues that there is insufficient evidence to establish 

    guilt beyond reasonable doubt.

    """
    
    # Example RAG summary
    sample_rag_summary = """

    Clearly, the evidence points toward acquittal. The case obviously lacks 

    substantial proof of guilt.

    """
    
    # Example historical cases
    sample_historical = [
        {"outcome": "conviction", "gender": "male", "region": "urban", "year": 2020},
        {"outcome": "acquittal", "gender": "female", "region": "rural", "year": 2020},
        {"outcome": "conviction", "gender": "male", "region": "urban", "year": 2021},
        {"outcome": "conviction", "gender": "female", "region": "urban", "year": 2021},
    ]
    
    # Run comprehensive analysis
    print("Running comprehensive legal analysis...\n")
    results = analyze_legal_case(
        case_text=sample_case,
        rag_summary=sample_rag_summary,
        source_documents=[sample_case],
        historical_cases=sample_historical,
        case_metadata={"case_type": "criminal", "jurisdiction": "Maharashtra"}
    )
    
    # Print results
    print(json.dumps(results, indent=2))