```python
def line_tag(body: str) -> str:
    if not isinstance(body, str):
        raise ValueError("Body must be a string")
    tag = sum(ord(char) for char in body) % 256
    return f"{tag:02x}"


def check_line(line: str) -> str:
    if not isinstance(line, str):
        raise ValueError("Line must be a string")
    if len(line) < 3:
        raise ValueError("Line must be at least three characters long")
    body = line[:-3]
    expected_tag = line[-2:]
    actual_tag = line_tag(body)
    if body[-1] != '~' or expected_tag != actual_tag:
        raise ValueError("Invalid line format")
    return body
```