... first != -1 and last != -1 and last > first:
        t = t[first:last + 1].strip()
    return t


def validate_schema(obj: dict, block_id: str) -> dict:
    """
    Enforce:
    {
      "block_id": "...",
      "codes": [ {"code": "...", "quote": "...", "line": "L0123"} ]
    }
    """
    if not isinstance(obj, dict):
        raise ValueError("Model output is not a JSON object")

    # block_id: fo...