def process_retriever_output(result: "FunctionExecutionResult") -> List[Dict[str, Any]]:
    """
    Process retriever output from result into mlflow.entities.Document format for tracing.

    Args:
        result: The result of the function execution to be processed.

    Returns:
        Retriever output formatted into a list of Documents.
    """
    if result.format == "CSV":
        df = pd.read_csv(StringIO(result.value))
        if "metadata" in df.columns:
            df["metadata"] = df["metadata"].apply(ast.literal_eval)
        output = df.to_dict(orient="records")
    else:
        value = result.value
        output = ast.literal_eval(value) if isinstance(value, str) else value

    return output

    Process retriever output from result into mlflow.entities.Document format for tracing.

    Args:
        result: The result of the function execution to be processed.

    Returns:
        Retriever output formatted into a list of Documents.
    
ai/core/src/unitycatalog/ai/core/utils/function_processing_utils.py