def extract_function_metadata(func: Callable[..., Any]) -> FunctionMetadata:
    """
    Extracts metadata from a Python function necessary for SQL function generation.

    This includes the function's signature, type hints, docstring information,
    parameters, and the function body.

    Args:
        func: The Python function to extract metadata from.

    Returns:
        FunctionMetadata: An object containing all extracted metadata.
    """

    func = unwrap_function(func)
    func_name = func.__name__
    signature = inspect.signature(func)
    type_hints = get_type_hints(func)

    sql_return_type = validate_return_type(func_name, type_hints)

    base_return_type_name = sql_return_type.split("<", 1)[0]

    docstring = inspect.getdoc(func)
    if not docstring:
        raise ValueError(f"Function '{func_name}' must have a docstring with a description.")
    docstring_info = parse_docstring(docstring)

    params_in_signature = set(signature.parameters.keys()) - set(FORBIDDEN_PARAMS)
    check_docstring_signature_consistency(docstring_info.params, params_in_signature, func_name)

    parameters = []
    position = 0
    for param_name, param in signature.parameters.items():
        if param_name in FORBIDDEN_PARAMS:
            raise ValueError(f"Parameter '{param_name}' is not allowed in the function signature.")

        if param.kind in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD):
            kind = (
                "var-positional (*args)"
                if param.kind == inspect.Parameter.VAR_POSITIONAL
                else "var-keyword (**kwargs)"
            )
            raise ValueError(
                f"Parameter '{param_name}' is a {kind} parameter, which is not supported in SQL functions."
            )

        if param_name not in type_hints:
            raise ValueError(f"Missing type hint for parameter: {param_name}.")

        param_hint = type_hints[param_name]

        try:
            sql_type = validate_type_hint(param_hint)
        except ValueError as e:
            error_message = generate_type_hint_error_message(param_name, param_hint, e)
            raise ValueError(error_message) from e

        base_type_name = sql_type.split("<", 1)[0]

        param_comment = docstring_info.params.get(param_name)
        if param_comment:
            param_comment = param_comment.replace("'", '"')

        parameter_default = None
        if param.default is not inspect.Parameter.empty:
            if is_collection_type(param_hint):
                raise ValueError(
                    f"Parameter '{param_name}' of type '{param_hint}' cannot have a default value."
                )
            if not is_valid_default_value(param.default, param_hint):
                raise ValueError(
                    f"Default value for parameter '{param_name}' does not match the type hint '{param_hint}'."
                )
            parameter_default = format_default_value(param.default)

        param_info = {
            "name": param_name,
            "sql_type": sql_type,
            "base_type_name": base_type_name,
            "comment": param_comment,
            "parameter_default": parameter_default,
            "param": param,  # Original inspect.Parameter object
            "position": position,
        }
        parameters.append(param_info)
        position += 1

    function_body, indent_unit = extract_function_body(func)

    return FunctionMetadata(
        func_name=func_name,
        signature=signature,
        type_hints=type_hints,
        sql_return_type=sql_return_type,
        base_return_type_name=base_return_type_name,
        docstring_info=docstring_info,
        parameters=parameters,
        function_body=function_body,
        indent_unit=indent_unit,
    )

    Extracts metadata from a Python function necessary for SQL function generation.

    This includes the function's signature, type hints, docstring information,
    parameters, and the function body.

    Args:
        func: The Python function to extract metadata from.

    Returns:
        FunctionMetadata: An object containing all extracted metadata.
    
ai/core/src/unitycatalog/ai/core/utils/callable_utils.py