def METHOD_NAME(offset: int = 0) -> str:
    """
    Captures the stack traceback and returns it as a string. If offset is positive,
    it will extract the traceback starting at OFFSET frames from the top (e.g. most recent frame).
    An offset of 1 means the most recent frame will be excluded.
    This is typically used for user function traceback so that we throw away
    unnecessary stack frames.
    """
    file = io.StringIO()
    tb_type, tb_val, tb = sys.exc_info()
    while offset > 0:
        if tb is None or tb.tb_next is None:
            break
        tb = tb.tb_next
        offset -= 1
    traceback.print_exception(tb_type, tb_val, tb, file=file)
    file.seek(0)
    return file.read()