```python
def line_tag(body: str) -> str:
    if not isinstance(body, str):
        raise ValueError("line_tag expects a string")
    return format(sum(ord(ch) for ch in body) % 256, "02x")


def check_line(line: str) -> str:
    if not isinstance(line, str) or len(line) < 3:
        raise ValueError("check_line expects a non-empty string of at least three characters")
    if line[-3] != '~':
        raise ValueError("The third-from-last character must be a tilde")
    tag = line[-2:]
    body = line[:-3]
    if tag != line_tag(body):
        raise ValueError("The tag does not match the body")
    return body
```