def layout_to_text(layout: dict, text: str) -> str:
    """
    Document AI identifies form fields by their offsets in the entirety of the
    document's text. This function converts offsets to a string.
    """
    response = ""
    # If a text segment spans several lines, it will
    # be stored in different text segments.
    for segment in layout.text_anchor.text_segments:  # type: ignore
        start_index = (
            int(segment.start_index)
            if segment in layout.text_anchor.text_segments  # type: ignore
            else 0
        )
        end_index = int(segment.end_index)
        response += text[start_index:end_index]

    # remove whitespace
    response = "".join(response.split("\n"))
    response = "".join(response.split(":"))
    return response.strip()