Skip to content

Validation

Input validation for clinical summary text.

Enforces minimum length and non-empty constraints before the summary enters the scoring pipeline. Used by both the CLI layer and the orchestrator.

validate_summary_text(summary)

Validate and clean a raw summary string.

Parameters:

Name Type Description Default
summary str | None

Raw summary text (may be None if user omitted input).

required

Returns:

Type Description
str

The whitespace-stripped summary text.

Raises:

Type Description
ValueError

If summary is None, empty/whitespace-only, or shorter than MIN_SUMMARY_CHARS after stripping.

Source code in src/grading_pipeline/validation.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def validate_summary_text(summary: str | None) -> str:
    """Validate and clean a raw summary string.

    Args:
        summary: Raw summary text (may be ``None`` if user omitted input).

    Returns:
        The whitespace-stripped summary text.

    Raises:
        ValueError: If ``summary`` is ``None``, empty/whitespace-only,
            or shorter than ``MIN_SUMMARY_CHARS`` after stripping.
    """
    if summary is None:
        raise ValueError(EMPTY_SUMMARY_ERROR)

    cleaned = summary.strip()
    if not cleaned:
        raise ValueError(EMPTY_SUMMARY_ERROR)

    if len(cleaned) < MIN_SUMMARY_CHARS:
        raise ValueError(SHORT_SUMMARY_ERROR)

    return cleaned