File size: 1,162 Bytes
7ee2ab0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Any, Tuple


def validate_submission(obj: Any) -> Tuple[bool, str]:
    """Validate VQA Answer Therapy submission format."""
    if not isinstance(obj, list):
        return False, "Submission must be a JSON list of result objects."
    if len(obj) == 0:
        return False, "Submission list is empty."
    for i, item in enumerate(obj):
        if not isinstance(item, dict):
            return False, f"Entry at index {i} must be a JSON object."
        if "question_id" not in item:
            return False, f"Entry at index {i} missing 'question_id'."
        if "single_grounding" not in item:
            return False, f"Entry at index {i} missing 'single_grounding'."
        if not isinstance(item["question_id"], str):
            return False, f"'question_id' at index {i} must be a string."
        sg = item["single_grounding"]
        if not isinstance(sg, (int, float)):
            return False, f"'single_grounding' at index {i} must be a float (0=multiple, 1=single)."
        if not (0.0 <= float(sg) <= 1.0):
            return False, f"'single_grounding' at index {i} must be between 0.0 and 1.0."
    return True, "OK"