langchain/prompts/base.py/validate_jinja2
def validate_jinja2(template: str, input_variables: List[str]) -> None:
    input_variables_set = set(input_variables)
    valid_variables = _get_jinja2_variables_from_template(template)
    missing_variables = valid_variables - input_variables_set
    extra_variables = input_variables_set - valid_variables

    error_message = ""
    if missing_variables:
        error_message += f"Missing variables: {missing_variables} "

    if extra_variables:
        error_message += f"Extra variables: {extra_variables}"

    if error_message:
        raise KeyError(error_message.strip())