from typing import Optional


def _get_bool(val) -> Optional[bool]:
    """
    Converts val to bool if can be done with certainty.
    If we cannot infer intention we return None.
    """
    if isinstance(val, bool):
        return val
    elif isinstance(val, str):
        if val.strip().lower() == 'true':
            return True
        elif val.strip().lower() == 'false':
            return False
    return None