Paper deep dive
Robust Hierarchical Structures for Agentic Document Analysis
Ruiying Ma, Yiming Lin, Aditya G. Parameswaran
Intelligence
Status: not_run | Model: - | Prompt: - | Confidence: 0%
Entities (0)
Relation Signals (0)
No relation signals yet.
Cypher Suggestions (0)
No Cypher suggestions yet.
Abstract
Abstract:Large Language Models (LLMs) enable us to better understand text documents, including PDFs and Word documents. However, LLMs, as well as more modern LLM agents, i.e., those with tool-calling abilities, typically treat such documents as plain text, ignoring the fact that they are often organized hierarchically into sections and subsections. Extracting this structure, while difficult, can improve efficiency and effectiveness for agents (and humans)---since only sections relevant to a given task need to be processed. Unfortunately, prior work on structure extraction provides no formal guarantees on how well the inferred structure matches the true one. Instead, we target a robust and compact variant that is feasible to infer and useful in practice. Robustness ensures that the text under each subsection header is a superset of the text under the same header in the true structure. Compactness seeks to minimize this superset, reducing agentic cost (or human cognitive load). We propose SHED, a two-stage workflow for inferring a robust and compact structure. The first stage is pluggable with an infinite family of approaches, each guaranteeing robustness for a specific document class. We theoretically characterize the document space using these classes and their hierarchical relationships. Empirically, SHED improves F-1 scores (measuring the robustness--compactness trade-off) by 13%--68% over non-LLM baselines and 9%--15% over expensive LLM-based approaches. Finally, we show how SHED-inferred structures are valuable for agentic document analysis: agents using SHED outperform baselines, achieving 3%--23% higher accuracy while being up to 10x cheaper.
Tags
Links
- Source: https://arxiv.org/abs/2609.33322v1
- Canonical: https://arxiv.org/abs/2609.33322v1
Trouble viewing inline? Open PDF directly →
Full Text
163,538 characters extracted from source content.
Expand or collapse full text
Robust Hierarchical Structures for Agentic Document Analysis Ruiying Ma Affiliation: UC Berkeley email: ruiyingm@berkeley.edu , Yiming Lin Affiliation: UC Berkeley email: yiminglin@berkeley.edu and Aditya G. Parameswaran Affiliation: UC Berkeley email: adityagp@berkeley.edu Abstract. Large Language Models (LLMs) enable us to better understand text documents, including PDFs and Word documents. However, LLMs, as well as more modern LLM agents, i.e., those with tool-calling abilities, typically treat such documents as plain text, ignoring the fact that they are often organized hierarchically into sections and subsections. Extracting this structure, while difficult, can improve efficiency and effectiveness for agents (and humans)—since only sections relevant to a given task need to be processed. Unfortunately, prior work on structure extraction provides no formal guarantees on how well the inferred structure matches the true one. Instead, we target a robust and compact variant that is feasible to infer and useful in practice. Robustness ensures that the text under each subsection header is a superset of the text under the same header in the true structure. Compactness seeks to minimize this superset, reducing agentic cost (or human cognitive load). We propose SHED, a two-stage workflow for inferring a robust and compact structure. The first stage is pluggable with an infinite family of approaches, each guaranteeing robustness for a specific document class. We theoretically characterize the document space using these classes and their hierarchical relationships. Empirically, SHED improves F-1 scores (measuring the robustness–compactness trade-off) by 13%–68% over non-LLM baselines and 9%–15% over expensive LLM-based approaches. Finally, we show how SHED-inferred structures are valuable for agentic document analysis: agents using SHED outperform baselines, achieving 3%–23% higher accuracy while being up to 10×10× cheaper. 1. Introduction (a) The header phrases and their visual patterns. (b) The true SHT. (c) A robust SHT. (d) Deep and wide SHTs. Figure 1. Hierarchical structures of a financial document Walmart Inc. form 10-K. The node viv_i in an SHT corresponds to the header phrase pip_i. Thanks to Large Language Models (LLMs), we are seeing a resurgence of interest in automatically processing the vast volumes of unstructured data in our organizations, including PDF and Word documents (Harbert, 2021; McDowell, 2023). Modern agentic LLMs with tool-calling (Yao et al., 2022), and systems built on them, such as Claude Code (Anthropic, 2025b), Codex (OpenAI, 2025), and Claude Cowork (Anthropic, 2026), are rapidly emerging as a dominant paradigm for reading, reasoning over, and querying long documents, a setting we term agentic document analysis. Yet processing long documents remains challenging for agents: reading them in full incurs high token costs and causes accuracy to degrade with context (i.e., input) length, a phenomenon known as “context rot” or “lost-in-the-middle” (Liu et al., 2024a; Hong et al., 2025). One solution is to simply provide more tools to the agents, such as regular expression-based search within documents, e.g., via grep (Sun et al., 2025b), or embedding-based search (Singh et al., 2025), which allow agents to retrieve and process portions of documents rather than all of it at once. However, such tools treat documents as a bag of words, ignoring their underlying hierarchical structure in the form of sections and subsections. Humans rely on this hierarchy—essentially a table of contents—to understand a document at a glance and navigate it efficiently; agents should too. Moreover, this hierarchy is common across domains: e.g., as of 2025, 17M+ SEC EDGAR filings (Wikipedia, 2025), 530K+ ClinicalTrials reports (U.S. National Library of Medicine, 2025), and 4M+ DOE OSTI reports (U.S. Department of Energy, Office of Scientific and Technical Information, 2025) have such structures. We therefore ask the question: how can we automatically and correctly identify this hierarchical structure—and can agents (and humans) make use of this structure for efficient and effective document analysis? Example 1 (Impact of Hierarchical Structure.). Consider a Walmart Inc. 10-K document with 170 pages in Figure 1. Its hierarchical structure can be represented as a tree shown in Figure 1(b), where nodes represent headers, and edges represent semantic (containment) relationships. Following Lin et al. (Lin et al., 2025b), we call this tree a Semantic Hierarchical Tree (SHT). For example, viv_i in Figure 1(b) corresponds to the header phrase pip_i in Figure 1(a), while edge v16→v20v_16→ v_20 indicates that the document portion headed by Consolidated Statements of Income (corresponding to v20v_20) is a subsection under the section titled ITEM 8… represented by v16v_16. Consider the question “What is the overall FY2018–FY2020 average operating income?”. The correct answer is in the subsection corresponding to v20v_20, with the header “Consolidated Statements of Income”, and content about operating income—retrieving and processing this entire subsection is sufficient to answer this question. However, an agent without the document hierarchy may use grep to retrieve portions of the content underlying v12v_12 and v20v_20 (the two boxes in Figure 1(b)), since the content is similar to the question, even though v12v_12 is a false positive, since it corresponds to the U.S. segment, and not overall. Without knowing the structure—and specifically the headers—for v12v_12 and v20v_20, it is impossible for the agent to know which one is accurate. Even worse, in other cases, the document portion retrieved may not be understandable in isolation (unlike section/subsection-level units that are more logically complete), requiring the agent to make a guess based on incomplete information. Like agents, human understanding of long documents hinges on SHTs (Swoopes et al., 2025), improving the accessibility of scientific (Che et al., 2024), legal (Ebbers et al., 2022), and medical (Petherbridge and Cotropia, 2016) documents. An SHT not only aids humans in locating which subsections they should review (top-down), but also provides them with context for where they are in the document when reviewing a given text portion (bottom-up) (Lemarié et al., 2012; Chung, 2000). For example, when reading the text containing “operating income” under v20v_20, the headers are essential to understand what the text refers to. Lack of guarantees in prior approaches. Past work on SHT inference from documents is based on LLMs (ContextGem, 2025; LlamaParse, 2025), custom models (Koreeda and Manning, 2021a; Wang et al., 2024), or rules (PyMuPDF, 2025; pdfminer.six, 2019), of which LLM-based approaches are currently considered state-of-the-art. Unfortunately, prior approaches for inferring SHTs provide no real guarantees for how well such SHTs match the “true” underlying SHT, except in very specific settings that are rare in practice, as we will discuss later (Lin et al., 2025b). In particular, LLM-based approaches similarly provide no guarantees, and also are expensive. In fact, as we will see later, they sometimes hallucinate, introducing headers that don’t exist in the underlying document. Overall, identifying the true SHT is unrealistic due to heterogeneous layouts, semantic ambiguity, and length (Zhang et al., [n. d.]). Robustness for SHTs. Instead of inferring the true SHT, we introduce a new objective of robustness. A robust SHT is one where, for each (section or subsection) header, we require the text “under it” to be a superset of the corresponding text in the true SHT. Robustness is essential for correctness, as discussed below: Example 2 (Robust Retrieval.). Figure 1(c) shows a robust SHT; the document portion corresponding to v22v_22 is now part of that of v20v_20, as the edge v16→v22v_16→ v_22 in the true SHT (1(b)) becomes a direct path connecting v16v_16 to v22v_22. When answering the question in Figure 1(b) using this robust SHT, suppose v20v_20 is retrieved and its document portion (where the correct answer resides) is returned to answer the question. Here, in addition to the portion providing the correct answer (i.e., one corresponding to v20v_20 in the true SHT), the extra portion corresponding to v22v_22 is also returned, which is permissible as long as all true portions (the ones corresponding to v20v_20) are included—as agents are able to filter out or ignore extraneous irrelevant content. Moreover, retrieving v20v_20 as a complete subsection, rather than keyword-matched fragments, ensures that the returned content is self-contained and interpretable. Compactness for SHTs. While a robust SHT guarantees that the returned context for any given header (i.e., the text portions underneath) is a superset of the true one, we also want to minimize the size of the returned context to reduce either processing cost for agents or human cognitive load, depending on the setting—we call this property compactness. Consider the deep SHT in Figure 1(d)-1, which forms a chain of nodes with a single leaf. This tree is robust but not compact (e.g., retrieving the context of v10v_10 returns all the content from p10p_10 to the end of the document). In contrast, the wide SHT in Figure 1(d)-2, where all nodes except v1v_1 are in the same layer, is compact but not robust (e.g., the document portion of v16v_16 no longer contains that of v22v_22, and v16v_16 is no longer an ancestor of v22v_22). We therefore aim to infer SHTs that are guaranteed to be robust, while being as compact as possible, ensuring correctness while reducing cost. (This is analogous to ensuring 100% recall, while maximizing precision, when retrieving document subsections.) Inferring a robust and compact SHT via SHED. Inferring an SHT that guarantees robustness and is compact is non-trivial. While current tools can identify headers accurately (Da et al., 2023; Ke et al., 2017), i.e., section or subsection headers, corresponding to nodes in the tree, they fail to assemble these (header) nodes into a robust tree. We propose SHED 11 1 Semantic Hierarchical Structure Extraction for Documents., a framework for inferring a robust and compact hierarchical structure for documents with visually identifiable structures, using only intrinsic document elements (e.g., (sub)section headers) without any external ontology. Intuitively, each header has specific human-interpretable visual patterns in the form of numbering, font, size, and capitalization. Headers with identical visual patterns are typically of the same type, and therefore belong in similar “levels” in the SHT, e.g., section headers are often formatted similarly, and would be at similar levels in the SHT. Taking phrases labeled as headers as input nodes, SHED employs a two-stage workflow: it first groups nodes with identical visual patterns into clusters and infers relationships among these clusters; it subsequently derives edges among nodes from the cluster relationships to assemble a compact SHT. The first stage is semantic depth (SD) inference, where SHED assigns each cluster a semantic depth. These semantic depths may differ from the depths in the true SHT, but their relative ordering indicates hierarchical relationships: the cluster of a node’s parent must have a smaller semantic depth than that of the node. We introduce two approaches for SD inference: local-first, which uses the header immediately prior to a cluster’s first occurrence to infer its semantic depth, and global-first, which uses all headers prior to that occurrence. The latter generalizes Lin et al.’s approach (Lin et al., 2025b), which only focuses on inferring the true SHT rather than robust variants, and only considers a narrow class of well-formatted documents that, as we will show in Section 4, are rare, occupying <<25% of real-world documents. The second stage, SHT assembly, constructs a compact SHT by deriving edges from the relative ordering of the inferred semantic depths, with tree depth bounded by the number of clusters, independent of the SD inference approach used in the first stage. SHED (with local-first) improves robustness and compactness by 13%–68% and 9%–15% in F-1 scores over non-LLM baselines and expensive LLM-based approaches, respectively. Characterization of Robustness Classes. Figure 2. Our contribution: Hierarchy of robustness classes. While our two-stage framework results in high robustness and compactness as we see in our experiments, we wanted to additionally characterize the space of documents for which we can guarantee robustness for each approach, and also go beyond the two SD inference approaches, local- and global-first. To do so, we establish a necessary and sufficient condition for robustness for each approach, a property we call SD conformance. Leveraging SD conformance, we construct a Venn-diagram of relationships for various approaches, as shown in Figure 2—this diagram shows the sets of documents for which each approach guarantees robustness. We prove that neither local- nor global-first dominate, but there is a class of documents we call depth-aligned, for which local-first guarantees robustness, but global-first does not. We further generalize beyond local- and global-first to an infinite family of approaches K, each guaranteed to return a robust SHT for a specific class of documents while optimizing for compactness. We additionally define a class of loosely-formatted documents which lies at the intersection of all approaches in K, including local- and global-first, and extends far beyond well-formattedness (by 2.57×2.57× empirically). To our knowledge, this is the first formal characterization of various document classes and effectiveness of the corresponding approaches. Application to Agentic Document Analysis. We demonstrate the practical usefulness of robust and compact SHTs for agentic document analysis, whose core needs are what we target, motivating SHED’s formulation, guarantees, and evaluations. Specifically, agents need structure for accurate and cost-efficient analysis of long, complex documents, and SHED precisely targets such structures: robustness (the text under each header is a superset of the true text) ensures that the agent gets all relevant content, while compactness bounds context size to mitigate context rot and provide lower cost. By providing an agent with the hierarchical structure inferred by SHED, the agent can retrieve the appropriate section or subsection at a time, outperforming agents without structures or those with baseline structures by 3%–23% in average accuracy, while reducing total costs by as much as 10×10× across four datasets. We make the following contributions in this paper: • We formalize the novel concepts of robustness and compactness of SHTs for document analytics (Section 2) and design SHED, a two-stage workflow with a first stage that is pluggable with an infinite family of approaches (Section 3–4). • We theoretically characterize various classes of documents for which SHED guarantees robustness while optimizing compactness (Section 4). • Across four datasets spanning various domains and layouts (Section 5), for SHT inference, SHED outperforms non-LLM baselines by 13%–68%, and significantly more expensive LLM-based approaches by 9%–15% in F-1 score, measuring the robustness-compactness trade-off (Section 6). • We demonstrate the practical usefulness of SHED for agentic document analysis, where providing hierarchical structure to agents improves average accuracy by 3%–23% while reducing total costs by up to 10×10× over baselines across four datasets (Section 7). • We additionally show that SHED’s scalability on changing number of documents or complexity is satisfactory. SHED still infers robust and compact SHTs, and has high QA accuracy at low cost, outperforming baselines by up to 4.5×4.5× (Section 8). 2. Robust Semantic Hierarchical Trees We focus on documents with rich visual formatting (e.g., PDF and Word files). We first review relevant concepts related to documents, including semantic hierarchical trees, as defined in (Lin et al., 2025b), in Section 2.1, and then define robust and compact variants in Section 4. 2.1. Preliminaries Documents and Phrases. Given a document D, we operate on a plain text serialized representation as a list of phrases, D=p1,p2,…,pn D=\p_1,p_2,...,p_n\, indexed based on where they appear in D. Each phrase pip_i is associated with a label li∈section_header,text,table,image,… l_i∈\ section\_header, text, table,\\ image,…\. This labeling can be performed at no cost using open-source document recognition tools (Da et al., 2023; Ke et al., 2017; Niu et al., 2025), which typically extract phrases in a top-down, left-to-right manner, consistent with the human reading order. Although different tools may define different label sets, labels such as section_header (which broadly refers to the headers such as titles, section and subsection headers) and text (representing content) are common, making it feasible to identify the hierarchical structure of a document as described below. We say a phrase is a header phrase if its label is section_header. Visual Pattern. Humans typically infer hierarchical structures from visual features of the header phrases such as font and layout position. For example, header phrases in larger, bold fonts that are centered may indicate section headers, whereas header phrases in smaller, non-bold fonts that are not centered may indicate subsection headers. We similarly rely on the visual patterns of phrases, defined below, to infer hierarchical structures. For each phrase pi∈Dp_i∈ D, let vp(pi)vp(p_i) be the visual pattern associated with pip_i, encoding various visual features. vp(pi)vp(p_i) is represented as a feature vector, with features such as [font_size,font_name,font_color,is_underlined,is_centered,is_capitalized,list_type,…] [ font\_size, font\_name, font\_color, is\_underlined,\\ is\_centered, is\_capitalized, list\_type,…]. Here, font_size, name, and color represent the style of the phrase. The remaining features capture aspects such as whether the phrase is underlined, center-aligned, fully capitalized, or part of a numeric or alphabetical list. Semantic Hierarchical Tree. We define a Semantic Hierarchical Tree (SHT) for a document D, given phrases pi∈Dp_i∈ D, their labels lil_i, and visual patterns vp(⋅)vp(·). Definition 1 (Semantic Hierarchical Tree.). An SHT for a document is a directed rooted tree T=(V,E)T=(V,E), with a one-to-one correspondence between the nodes V and the header phrases. Let viv_i denote the node corresponding to the header phrase pip_i with index i. For any two nodes vi,vj∈Vv_i,v_j∈ V, where i<ji<j, viv_i must precede vjv_j in the pre-order traversal of the tree. Note that the node set V=vi1,vi2,…,vinV=\v_i_1,v_i_2,…,v_i_n\ corresponds to a subset of the phrases Pi⊆D,Pi=pi1,pi2,…,pinP_i D,P_i=\p_i_1,p_i_2,…,p_i_n\, namely, only those that are header phrases, and thus indices i1,i2,…,ini_1,i_2,…,i_n are not necessarily consecutive. Definition 1 additionally implies that the indices of viv_i and its descendants are smaller than those of any right sibling of viv_i (if any). For example, “Section 2” and all its subsection headers should appear before “Section 3”. Further note that V is fixed (comprising all header phrases pi1,…,pinp_i_1,…,p_i_n), while E is not, admitting multiple valid SHTs for the same document. We define the true SHT as the one that human users believe best reflects the document’s hierarchical structure. Example 2. Figure 1(b) shows the (partial) true SHT for Walmart Inc. form 10-K. v16v_16 corresponds to p16p_16; its child v20v_20 corresponds to p20p_20, a subsection header of p16p_16. The pre-order traversal preserves a strictly increasing sequence of node indices, v1,…,v10,…,v22v_1,…,v_10,…,v_22. Text Span. The text span of a node viv_i, denoted by ts(vi)ts(v_i), refers to the text portions (i.e., phrases) associated with viv_i in D. Given an SHT T, ts(vi)ts(v_i) denotes the sequential list of phrases starting from the header phrase corresponding to viv_i and ending immediately before the header phrase corresponding to the next non-descendant node vjv_j in T, defined below, i.e., [pi,pi+1,…,pj−1][p_i,p_i+1,…,p_j-1]. Formally, node vjv_j is a non-descendant of viv_i in T with the smallest index j>ij>i. For example, the text span of v20v_20 in 1(b) is [p20,p21][p_20,p_21], since its next non-descendant node is v22v_22. 2.2. Robust and Compact SHTs Constructing the true SHT may be unrealistic due to semantic ambiguities in documents. A key insight of this paper is that it is often sufficient to construct a robust SHT for downstream tasks, rather than the true one, as defined below. Definition 3 (Robust SHT.). An SHT T of a document D is robust if ∀vi∈V∀~v_i∈ V, ts′(vi)⊆ts(vi)ts (v_i) ts(v_i), where ts′ts and tsts denote the text spans inferred from T′T (the true SHT) and T, respectively. A robust SHT T guarantees that the text span ts(vi)ts(v_i) of any node viv_i in T is a superset of that of viv_i in the true SHT T′T . This robustness property provides correctness guarantees for many tasks. For example, when performing retrieval (e.g., as part of agentic document processing) over a robust SHT T, the retrieved context for viv_i will always include the true context for viv_i in T′T . This property ensures correctness of question answering as long as the retrieval method identifies the right header (e.g., section header) where the answer lies, and the LLM gives the right answer when provided a superset of the text portion under this header (i.e., its text span). Example 4. Figure 1(c) presents a robust tree T related to the true one T′T in Figure 1(b), where v22v_22 is now a child of v20v_20. ts(v20)ts(v_20) contains ts′(v20)ts (v_20) and ts′(v22)ts (v_22), forming a superset of the true context ts′(v20)ts (v_20) that includes the answer to the question in Figure 1(a). A robust SHT also guarantees that any parent-child pairs in the true SHT remain as ancestor-descendant pairs, a property we will use for SHT inference in the following sections. The formal statement is given below and proved in Appendix A.1: Theorem 5. Consider an SHT T of a document D. T is robust if and only if for every pair of nodes vi,vjv_i,v_j where vjv_j is a child of viv_i in the true SHT T′T , vjv_j is a descendant of viv_i in T. While we want T to be robust, at the same time, we must optimize T for efficiency by minimizing the text span of each node. For example, when retrieving using T, the retrieved context for node viv_i is its text span ts(vi)ts(v_i) in T. While ts(vi)ts(v_i) must include the true text span ts′(vi)ts (v_i), it should also contain as little excess content ts(vi) s′(vi)ts(v_i) ts (v_i) as possible. Therefore, to minimize the text span of each node of T while preserving robustness, we want to minimize =∑vi∈Vts(vi) s′(vi) C= _v_i∈ Vts(v_i) ts (v_i); we refer to C as compactness. We can now formally define our problem. Definition 6 (Robust and Compact SHT Inference.). Given a document D=p1,…,pnD=\p_1,…,p_n\, where each phrase pip_i has a label lil_i and visual pattern vp(pi)vp(p_i), infer an SHT T from D such that T is robust, while minimizing compactness =∑vi∈Vts(vi) s′(vi) C= _v_i∈ Vts(v_i) ts (v_i). Example 7. For the SHTs of the Walmart Inc. form 10-K, we prefer 1(c) over the deep and wide SHTs in 1(d). The wide SHT is not robust: ts(v16)ts(v_16) incorrectly excludes ts′(v20)ts (v_20). The deep SHT is not compact: ts(v20)ts(v_20) unnecessarily includes all content from p20p_20 to the end of D. In contrast, 1(c) achieves robustness, while also being more compact. For robustness, ts(v16)ts(v_16) is a superset of its true text span, including ts′(v20)ts (v_20). For compactness, ts(v20)ts(v_20) includes only the small text span of v22v_22 in addition to ts′(v20)ts (v_20). 3. SHT Inference: Two Approaches In this section, we present our two-stage workflow, SHED, for inferring a robust and compact SHT T=(V,E)T=(V,E) from a document D, starting with an overview in Section 3.1. As mentioned earlier, the set of nodes V corresponds to the set of header phrases. To assemble V into an SHT T, we rely on the intuition that the semantic hierarchy represented by an SHT depends on the visual patterns of nodes vp(⋅)vp(·). Recall that these visual patterns are represented by feature vectors that encode various visual features (e.g., font_size, font_name) of the phrases corresponding to the nodes. 3.1. Overall Workflow The overall workflow of SHT inference consists of two stages: 1) Semantic depth (SD) inference (Section 3.2 and Section 3.3). The semantic relationships between nodes (i.e., the edges in the SHT) closely correspond to their visual patterns: certain visual patterns (e.g., those of section headers) tend to indicate parent nodes, while others (e.g., those of subsection headers) indicate children. Therefore, we first cluster the nodes based on their visual patterns—so each visual pattern corresponds to a cluster—and then infer what we refer to as the semantic depth of each cluster. Semantic depth does not directly specify the exact “level” of nodes with the given visual pattern in the SHT; instead, it constrains semantic relationships among nodes with different visual patterns (i.e., edges in the SHT), as described below. 2) SHT assembly (Section 3.4). We then build the SHT T by inferring edges based on semantic depths of the clusters. Specifically, we use the relative ordering of semantic depths to determine the allowed semantic relationships: the parent of a node in the SHT must belong to a cluster with a smaller semantic depth. As shown in Figure 3, there are multiple approaches for SD inference Infer-SD1,Infer-SD2,… Infer-SD_1, Infer-SD_2,…; the approaches in Sections 3.2 and 3.3 correspond to Infer-SD1 Infer-SD_1, which we refer to as local-first, and Infer-SD2 Infer-SD_2, which we refer to as global-first, respectively. Both local- and global-first approaches rely on the node with the smallest index in each cluster to determine the semantic depth of each cluster. This node, which we call the indexing node of the cluster, corresponds to the first occurrence of the visual pattern associated with the cluster in the document. The local-first approach infers the semantic depth of each cluster using local structural cues, examining only the node whose header phrase immediately precedes that of the cluster’s indexing node. In contrast, global-first uses global structural cues by considering all nodes whose header phrases precede that of the indexing node. Within our two-stage workflow, both approaches produce correct and compact SHTs, as we show in Section 3.5. The robustness of the SHTs inferred by local- and global-first approaches will be analyzed in Sections 4.1 and 4.2. We further combine local- and global-first into an infinite family of approaches in Section 4.3. Each approach in this family also ensures SHT robustness for a particular class of documents, as shown in Section 4.4. The global-first approach generalizes ZenDB’s inference algorithm (Lin et al., 2025b), which was restricted to well-formatted documents. We show in Section 4.4 that well-formatted documents constitute only a small subset of real-world documents, and the global-first approach, as a generalization within our two-stage framework, infers robust SHTs for a substantially broader class of documents. We begin by discussing our first SD inference approach. Figure 3. The overall workflow of SHED for SHT Inference. 3.2. Semantic Depth Inference: Local-First In local-first SD inference, we start by clustering the header nodes V, based on their visual patterns, into clusters =C1,…,CmC=\C_1,…,C_m\. Two nodes vi,vj∈Vv_i,v_j∈ V belong to the same cluster if they share identical visual patterns, i.e., vp(pi)=vp(pj)vp(p_i)=vp(p_j). For each cluster CjC_j, we will infer its semantic depth, denoted sd(Cj)sd(C_j). We assume that cluster C1C_1 contains only the root node v1v_1 and set its sd(C1)=0sd(C_1)=0. Next, we describe the inference of sd(C)sd(C) for each subsequent cluster. We leverage the local-first property, i.e., inferring semantic depth using the node that immediately precedes the indexing node of each cluster, as detailed below. We infer sd(Cj)sd(C_j) from the node viv_i whose header phrase pip_i is the first instance of the visual pattern corresponding to CjC_j encountered in the document. Formally, let i=ind(Cj)i=ind(C_j) denote the index of a cluster, defined as the smallest index among the indices of the nodes belonging to CjC_j. We call vind(C)v_ind(C) the indexing node of C. For example, if a cluster C2=v10,v16C_2=\v_10,v_16\, its index is ind(C2)=10ind(C_2)=10, and v10v_10 is its indexing node. We use C(v)C(v) to denote the cluster that contains node v. (a) Local-first. (b) Global-first. Figure 4. Intuition of SD Inference. (a) Algorithm 1 (b) Algorithm 2 (c) Algorithm 3 Figure 5. An illustration of SHT inference. For the indexing node viv_i of a cluster CjC_j, suppose vkv_k is the node with the largest index k<ik<i. In other words, vkv_k immediately precedes viv_i in the pre-order traversal of the true SHT T′T , indicating one of the following two cases, as shown in 4(a): 1 vkv_k is the true parent of viv_i, or 2 vkv_k is a descendant of the true parent of viv_i in T′T —but we are unaware of which case we are in. Recall that, to ensure robustness, we require the true parent of viv_i to remain an ancestor in the inferred SHT, as stated in Theorem 5. If we move viv_i to be a child of vkv_k, the true parent of viv_i in T′T remains an ancestor of viv_i in T, ensuring robustness. Based on this intuition, we assign C(vi)C(v_i) a larger semantic depth than C(vk)C(v_k). Note, however, that the latter case 2 may lead to reduced compactness, but we accept this compactness cost to ensure robustness. Algorithm 1 Infer-SD1(V,) Infer-SD_1(V,C) // Local-First 1: sd(C1)←0sd(C_1)← 0 2: for C∈\C1C \C_1\ in ascending order of ind(C)ind(C) do 3: vk←argmaxvi∈V,i<ind(C):iv_k← _v_i∈ V,i<ind(C):i 4: sd(C)←sd(C(vk))+1sd(C)← sd(C(v_k))+1 5: return sdsd ⊳ a mapping from a cluster to its semantic depth Algorithm 1 shows local-first SD inference. Starting with sd(C1)=0sd(C_1)=0 (Line 1), we scan the clusters in increasing order of their indices (Line 2-4). For cluster C, we find vkv_k with the largest index k<ind(C)k<ind(C) (Line 3). We then set sd(C)sd(C) to be sd(C(vk))+1sd(C(v_k))+1 to ensure robustness of the SHT inferred subsequently. The scanning order of Algorithm 1 ensures that sd(C(vk))sd(C(v_k)) has already been inferred when computing sd(C)sd(C), since ind(C(vk))≤k<ind(C)ind(C(v_k))≤ k<ind(C) (Line 2). Example 1. 5(a)illustrates Algorithm 1 using only the nodes explicitly shown in 1(c), with all other nodes hidden for simplicity. For example, to infer sdsd for C4C_4, we identify the node vk=v16v_k=v_16 immediately prior to its indexing node v20v_20 and assign sd(C4)=sd(C(v16))+1=sd(C2)+1=2sd(C_4)=sd(C(v_16))+1=sd(C_2)+1=2. 3.3. Semantic Depth Inference: Global-First Next, we provide an alternate global-first approach for SD inference22 2 As mentioned earlier, Algorithm 2 generalizes ZenDB’s algorithm to work on non-well-formatted documents, and leverages the two-stage approach; see details in Appendix C. (Algorithm 2). Like Algorithm 1, Algorithm 2 assigns semantic depths to clusters based on their indices: clusters with smaller indices (i.e., visual patterns whose first occurrence appears earlier in the document) have smaller semantic depths. Formally, after sorting the clusters in increasing order of their indices (Line 2), Algorithm 2 assigns each cluster C a semantic depth that is one greater than the largest semantic depth among all preceding clusters (Line 3-4). Algorithm 2 Infer-SD2(V,) Infer-SD_2(V,C) // Global-First 1: sd(C1)←0sd(C_1)← 0 2: for C∈\C1C \C_1\ in ascending order of ind(C)ind(C) do 3: vk←argmaxvi∈V,i<ind(C):sd(C(vi))v_k← _v_i∈ V,i<ind(C):sd(C(v_i)) 4: sd(C)←sd(C(vk))+1sd(C)← sd(C(v_k))+1 5: return sdsd In effect, the semantic depth of each cluster C is determined globally via its indexing node vind(C)v_ind(C): Algorithm 2 considers all nodes with smaller indices than vind(C)v_ind(C). We do not know which of these nodes is the true parent of vind(C)v_ind(C) (shown as purple arrows in 4(b)), so we opt for the worst case and set sd(C)sd(C) to be one larger than the largest semantic depth among their clusters, ensuring that sd(C)sd(C) is greater than the semantic depth of the cluster of the true parent of vind(C)v_ind(C), as illustrated in 4(b). Example 2. Using the same nodes and clusters as in 5(a), Algorithm 2 infers sd(Ci)=i−1 sd(C_i)=i-1 for each i∈[1,5] i∈[1,5], with sd(Ci)<sd(Cj) sd(C_i)<sd(C_j) whenever i<j i<j, as shown in 5(b). 3.4. SHT Assembly Given nodes V and inferred semantic depths sdsd of their clusters C (using local- or global-first), we now assemble T by inferring the parent of each non-root node in V. We infer the parents of nodes in increasing order of node indices, just as humans make sense of the structure of a document by reading the document sequentially. Suppose we have a partial SHT T containing all nodes with indices smaller than i, and we now infer the parent vkv_k of node viv_i. Let vjv_j denote the true parent of viv_i (which is unknown). Using the information available (i.e., V,V,C, and sdsd), we can derive conditions that the true parent vjv_j must satisfy, so that selecting vkv_k ensures robustness while optimizing compactness =∑v∈Vts(v) s′(v) C= _v∈ Vts(v) ts (v). For simplicity, we assume that T is the (partial) true SHT, i.e., T matches the true SHT so far. We define candidate parents of viv_i as the nodes that satisfy conditions 1) and 2) as stated below; this set must include the true parent vjv_j. We then select vkv_k from this set to ensure robustness and optimize compactness, without knowing vjv_j. 1) Coverage of Text Span: pi∈ts(vj)p_i∈ ts(v_j); i.e., the text span of vjv_j inferred from T must contain the header phrase pip_i of viv_i (e.g., a subsection header is contained within its parent section). Since all nodes in T have indices smaller than i, we have j<ij<i, and pi∈ts(vj)p_i∈ ts(v_j) further implies that vjv_j lies on the rightmost path of T, as described below, with its text span extending to the end of the document: ts(vj)=[pj,…,pn]ts(v_j)=[p_j,…,p_n], where j<i<nj<i<n and pnp_n denotes the final phrase of the document. The rightmost path of T starts from the root and follows the rightmost child at each node down to a leaf. In 5(c)(5), [v1,v16,v20,v22][v_1,v_16,v_20,v_22] is the rightmost path. From 1) alone, the candidate parents for viv_i are the nodes on the rightmost path of T. We can therefore select vkv_k as the candidate with the largest index (i.e., the rightmost leaf of T), inserting viv_i at the end of the rightmost path, guaranteeing that the true parent vjv_j remains an ancestor of viv_i, and ensuring robustness. However, this choice of vkv_k yields worst-case compactness: ts(vi)ts(v_i) is added to the text span of every node on the rightmost path, contributing r times to compactness C, where r is the number of candidate parents. To reduce r and improve compactness, we introduce 2) to further narrow the set of candidate parents. 2) Semantic Depth Constraint: sd(C(vj))<sd(C(vi))sd(C(v_j))<sd(C(v_i)). Recall that semantic depths of clusters constrain semantic relationships between nodes: the semantic depth of a parent’s cluster must be smaller than that of the child’s cluster, i.e., sd(C(vj))<sd(C(vi))sd(C(v_j))<sd(C(v_i)). Condition 2) uses semantic depths sdsd to further restrict the set of candidate parents to nodes on the rightmost path of T whose clusters have smaller semantic depths than C(vi)C(v_i). This set still contains the true parent vjv_j while reducing the number of candidate parents r. Selecting vkv_k as the candidate parent with the largest index preserves robustness of T, since both vkv_k and vjv_j lie on the rightmost path with k≥jk≥ j, implying that vkv_k is equal to or a descendant of vjv_j. This choice of vkv_k also improves compactness of T, as the reduced set of candidate parents leads to a smaller r than using 1) alone. Algorithm 3 Assemble-SHT(V,,sdV,C,sd) 1: T←T← an empty tree 2: for vi∈Vv_i∈ V in ascending order of their indices do 3: vk←argmaxvj∈T,pi∈ts(vj),sd(C(vj))<sd(C(vi)):jv_k← _v_j∈ T,p_i∈ ts(v_j),sd(C(v_j))<sd(C(v_i)):j 4: Add node viv_i to T as the rightmost child of vkv_k 5: return T Using the above two conditions, we can now present the algorithm to assemble an SHT T in Algorithm 3. We consider the nodes in increasing order of their indices (e.g., from v1,v10v_1,v_10 to v22v_22) (Line 2). In each iteration, we insert viv_i into T as the rightmost child of the selected parent vkv_k (Line 4), so that the pre-order traversal of T remains consistent with the nodes’ indexing order and thus with the document’s reading order. As mentioned earlier, vkv_k is selected as the candidate parent of viv_i with the largest index, from among all vjv_j in T that satisfy: 1) pi∈ts(vj)p_i∈ ts(v_j), and 2) sd(C(vj))<sd(C(vi))sd(C(v_j))<sd(C(v_i)). Note that the text span ts(vj)ts(v_j) of each node vjv_j evolves as new nodes are inserted into T. Therefore, in Line 3, ts(vj)ts(v_j) denotes the text span of vjv_j inferred from the partial tree T at that point in the algorithm. Example 3. 5(c)illustrates Algorithm 3 using the nodes, clusters, and semantic depths from Figure 5(a). When inserting v20v_20 (step (4)), the candidate parents—nodes in T with sd<sd(C(v20))=2 sd<sd(C(v_20))=2 (blue) and text spans covering p20p_20 (orange)—are v1v_1 and v16v_16. Since v16v_16 has the larger index, v20v_20 is inserted as its rightmost child. 3.5. Correctness and Compactness We now establish that our two-stage workflow correctly generates an SHT. We also show that the resulting SHT has good compactness. Correctness and compactness hold for any document and are independent of the SD inference approach. With respect to robustness, different SD inference approaches apply to different classes of documents. We analyze these document classes in Section 4. 3.5.1. SHT Correctness We can formally show that the tree T inferred by our two-stage workflow is an SHT: Theorem 4. The tree T output by Algorithm 3 is an SHT. Proof is in Appendix A.2. In brief, each node, when added, preserves the reading order thanks to condition 1) in Section 3.4. 3.5.2. SHT Compactness We now show that SHTs inferred by our workflow have good compactness (irrespective of algorithm). While true compactness =∑v∈Vts(v) s′(v) C= _v∈ Vts(v) ts (v) is hard to quantify without the true SHT T′T , a suitable proxy is the depth of the inferred SHT T, defined as the number of nodes on the longest root-to-leaf path. Deeper SHTs tend to be less compact: as SHED’s SHT depth ratio to the true SHT (i.e., depth(T)/depth(T′T )) grows from ≤1≤1 to 2.22.2, average compactness drops from 0.92 to 0.83 (Appendix E.2). We therefore use bounded depth as a proxy for good compactness, without claiming optimality with respect to compactness. Regardless of the SD inference approach used, the depth of an SHT T inferred by Algorithm 3 is bounded by the number of clusters (i.e., the number of distinct visual patterns among headers), since the path from any node to the root consists of strictly decreasing semantic depths, terminating at zero. In contrast, a deep SHT TdT_d that links all nodes into a single chain (1(d)-1) has depth equal to the number of tree nodes. Since the number of clusters is usually much smaller than the number of tree nodes, T is more compact than TdT_d, as shown on 600 real-world documents (Appendix D). 4. Robustness Analysis and Hierarchy In this section, we analyze the robustness of SHTs from different SD inference approaches. We first identify document classes that ensure robustness for arbitrary semantic depths in Section 4.1. These classes satisfy a property that we call semantic depth conformance, which depends on the inferred semantic depths; different semantic depths therefore induce different document classes where robustness is met. Next, in Section 4.2, we compare robustness guarantees of local- (Section 3.2) and global-first (Section 3.3) SD inference. We also identify a document class for which local-first guarantees robustness while global-first does not. Then, in Section 4.3, we generalize local- and global-first by combining them into an infinite family of SD inference approaches. In Section 4.4, we summarize all proposed document classes by showing hierarchical relationships among them via a Venn diagram. In Section 4.5, we compare SHED with ZenDB (Lin et al., 2025b). Overall, this section completes our formal study of robust and compact SHT inference (Section 2.2), complementing the correctness and compactness analyses (Section 3.5). We establish guarantees of perfect robustness, and characterize when they hold so that users can select approaches based on document characteristics. 4.1. Semantic Depth Conformance Consider a document D, its true SHT T′T , and node clusters C. We now establish a property of a document under which the SHT T returned by Algorithm 3 is guaranteed to be robust for any given assignment of semantic depths sdsd to clusters. To ensure robustness of T, Theorem 5 requires that every parent-child pair (vj,vi)(v_j,v_i) in the true SHT T′T remains an ancestor-descendant pair in T, which can be achieved by Algorithm 3 only if sd(C(vj))<sd(C(vi))sd(C(v_j))<sd(C(v_i)), a cluster-level relationship encoded by the relative ordering of semantic depths, as enforced by condition 2) in Section 3.4. In other words, for any true parent-child pair in T′T , the parent’s cluster must have a smaller semantic depth than the child’s cluster, a document property we refer to as semantic depth conformance and formalize in Theorem 1, so that Algorithm 3 permits the parent to remain as an ancestor of the child in T. But, perhaps surprisingly, this property is sufficient to also guarantee robustness. For convenience, we define sd(v)=sd(C(v))sd(v)=sd(C(v)) for any node v∈Vv∈ V. Theorem 1 (SD Conformance Equals SHT Robustness.). Consider a document D, with nodes V and clusters C. Let T be the SHT inferred by Algorithm 3, and T′T be the true SHT. Given semantic depths sdsd of the clusters inferred by an arbitrary SD inference approach, T is robust if and only if ∀vi,vj∈V~∀~v_i,v_j∈ V, whenever vjv_j is the parent of viv_i in T′T , it holds that sd(vj)<sd(vi).sd(v_j)<sd(v_i). We prove Theorem 1 in Appendix A.3. Note that when semantic depths are inferred using global-first, SD conformance reduces to requiring ind(C(vj))<ind(C(vi))ind(C(v_j))<ind(C(v_i)) for any parent-child pair (vj,vi)(v_j,v_i) in the true SHT, because the ordering of semantic depths is consistent with the indices of the corresponding clusters. 4.2. Local vs. Global-First Depth Inference To compare local- and global-first approaches, we first distinguish them using two concrete examples in Section 4.2.1: one where local-first infers a robust SHT while global-first fails, and vice versa. Then, in Section 4.2.2, we characterize a class of documents for which local-first guarantees robustness, whereas global-first does not. 4.2.1. Illustrative Scenarios (a) True SHT (b) Algorithm 1 (c) Algorithm 2 (d) True SHT (e) Algorithm 1 (f) Algorithm 2 (g) Clusters Figure 6. An example in which local-first generates a robust SHT while global-first does not (Figures 6(a), 6(b), 6(c)), and vice versa (Figures 6(d), 6(e), 6(f)). Colors indicate the cluster membership of each node in 6(g). Consider documents D1,D2D_1,D_2 with true SHTs shown in Figures 6(a) and 6(d), respectively. The clusters are indicated by colors in 6(g) (e.g., C5=v15 C_5=\v_15\ in D1D_1 and v15,v20 \v_15,v_20\ in D2D_2). For both documents, local-first assigns semantic depths sd1(C1,2,3,4,5)=0,1,2,3,2 sd_1(C_1,2,3,4,5)=0,1,2,3,2; global-first assigns sd2(C1..5)=0,1,2,3,4 sd_2(C_1..5)=0,1,2,3,4. When SD conformance holds, the corresponding approach infers a robust SHT: local-first in D1D_1 under sd1sd_1 and global-first in D2D_2 under sd2sd_2 (Figures 6(b) and 6(f)). When SD conformance is violated, non-robust SHTs result: global-first in D1D_1 due to sd2(v15)>sd2(v17)sd_2(v_15)>sd_2(v_17) and local-first in D2D_2 due to sd1(v17)>sd1(v20)sd_1(v_17)>sd_1(v_20) (Figures 6(c) and 6(e)). 4.2.2. A Document Class Favoring Local-First Inference We next identify a document class for which local-first guarantees robustness, while global-first does not (e.g., the document whose true SHT is in 6(a)). We call this class depth-aligned and provide a detailed explanation, as well as a proof, in Appendix A.4. Definition 2 (Depth-Aligned Documents.). A document D, with nodes V, clusters C, and true SHT T′T is depth-aligned if 1) ∀C∈∀~C , vind(C)v_ind(C), whenever it is not the root, is the leftmost child of its parent in T′T , and 2) for any vi,vj∈Vv_i,v_j∈ V such that C(vi)=C(vj)C(v_i)=C(v_j), viv_i and vjv_j are at the same level in T′T . For a depth-aligned document, the semantic depth assigned by local-first matches the true depth (i.e., the number of edges from the root to the node) of every node in its true SHT, guaranteeing SD conformance and thus robustness: Theorem 3. Consider a document D, with nodes V, clusters C, and true SHT T′T . Let sdsd denote the semantic depths inferred by local-first SD inference, and let T denote the SHT inferred by Algorithm 3 from sdsd. If D is depth-aligned, then ∀vi∈V∀~v_i∈ V, sd(vi)sd(v_i) equals the depth of viv_i in T′T , and T is robust. 4.3. Semantic Depth Inference Family We can further generalize SD inference by combining local- and global-first approaches into an infinite family of approaches. Recall that local-first assigns sd1(C)sd_1(C) to be one greater than sd1sd_1 of the cluster corresponding to the node immediately prior to its indexing node (Algorithm 1), while global-first scans all nodes prior to its indexing node and assigns sd2(C)sd_2(C) as one greater than the largest sd2sd_2 among their clusters (Algorithm 2). We extend these two approaches by combining sd1sd_1 and sd2sd_2 linearly as sd(C)=(K(C)⋅sd1+(1−K(C))⋅sd2)+1sd(C)= (K(C)· sd_1+(1-K(C))· sd_2 )+1, where K(C)∈[0,1]K(C)∈[0,1] is a cluster-specific parameter. Setting K(C)=1(0)K(C)=1(0) for all clusters recovers the local-first (global-first) approach. Arbitrary mappings K:→[0,1]K:C→[0,1] define an infinite family of SD inference approaches K, each denoted as Infer-SDK Infer-SD_K; pseudo code can be found in Appendix B. Infer-SDK Infer-SD_K guarantees SHT robustness whenever the input document satisfies SD conformance (Theorem 1). Because SD conformance depends on the semantic depths sdsd inferred by Infer-SDK Infer-SD_K, different KKs induce different sdsds and thus different conformance conditions. Therefore, the document classes that are necessary and sufficient to guarantee robustness for Infer-SDK Infer-SD_K vary across different parameter mappings K. In Section 4.4, we identify a document class, termed loosely-formatted documents, which lies at the intersection of all such document classes, guaranteeing robustness for all approaches in K induced by varying the mappings K. 4.4. Hierarchy of Robustness In this section, we study two additional document classes: well-formatted documents proposed by Lin et al. (Lin et al., 2025b), and what we term loosely-formatted documents, which encompasses well-formatted documents and ensures SHT robustness for the family of SD inference approaches, K, introduced in Section 4.3. We then summarize the relationships between all document classes considered thus far in the form of a hierarchy in Figure 2 and estimate their frequencies, as well as document classes that satisfy SD conformance for different approaches in K. Well-formatted Documents. In a well-formatted document, any pair of sibling nodes (i.e., nodes with the same parent) in the true SHT T′T belongs to the same cluster. Additionally, for any parent-child node pair in T′T , this relationship (i.e., which node is the parent and which is the child) is consistent with the parent-child relationship observed at the first occurrence of their corresponding visual patterns33 3 This statement is equivalent to ZenDB’s original definition of well-formattedness (Definition 1 in (Lin et al., 2025b)), which we will establish in Appendix C.. Concretely, in T′T , if viv_i is the parent of vjv_j, then, at the first occurrence of the visual pattern corresponding to vjv_j (i.e., at node vlv_l, the indexing node of C(vj)C(v_j)), vlv_l’s parent vkv_k has a visual pattern that matches viv_i. Here, (vk,vl)(v_k,v_l) is the first parent-child occurrence of the visual patterns corresponding to (vi,vj)(v_i,v_j). For well-formatted documents, any approach in K produces robust SHTs after applying Algorithm 3. However, these documents constitute a small fraction of real-world documents, e.g., 23.39% across 600 real-world documents (Appendix D). So, instead, we define a broader document class below, called loosely-formatted documents, and prove that they also guarantee robustness for all approaches in K in Theorem 6. Since well-formatted documents are a special case of loosely-formatted documents (see Theorem 5 below), their robustness guarantees follow immediately. Loosely-formatted Documents. These documents relax well-formattedness by removing the requirement that siblings belong to the same cluster. And the requirement that each parent-child relationship in the true SHT matches the first parent-child occurrence of the corresponding visual patterns is replaced by the weaker requirement that it matches the first ancestor-descendant occurrence of the corresponding visual patterns. Concretely, in T′T , if viv_i is the parent of vjv_j, then vlv_l must have an ancestor vkv_k whose visual pattern is the same as that of viv_i, where (vk,vl)(v_k,v_l) is the first ancestor-descendant occurrence of the visual patterns corresponding to (vi,vj)(v_i,v_j). For example, for the node pair (vi,vj)=(v1,v16)(v_i,v_j)=(v_1,v_16) in 1(b), their corresponding visual patterns first appear as an ancestor-descendant pair at (vk,vl)=(v1,v10)(v_k,v_l)=(v_1,v_10). This ancestor-descendant relationship correctly indicates the parent-child relationship between v1v_1 and v16v_16. Definition 4 (Loosely-Formatted Documents.). A document D, with nodes V, clusters C, and true SHT T′T is loosely-formatted if ∀vi,vj∈V∀~v_i,v_j∈ V, when viv_i is the parent of vjv_j in T′T , there exists a pair of nodes vk,vl∈Vv_k,v_l∈ V such that vkv_k is an ancestor of vlv_l in T′T with l=ind(C(vj))l=ind(C(v_j)) and C(vk)=C(vi)C(v_k)=C(v_i). As mentioned earlier, loosely-formatted documents relax well-formattedness, as stated below and proved in Appendix A.5. Theorem 5. Every well-formatted document is also loosely-formatted, but the converse does not hold. We further establish that applying our two-stage workflow with any SD inference approach from K on loosely-formatted documents guarantees robustness; proof can be found in Appendix A.6. Theorem 6 (Loose-Formattedness Implies SHT Robustness.). Let T be the SHT inferred by Algorithm 3 after applying any approach from K for SD inference on a document D. If D is loosely-formatted, then T is robust. Hierarchy of Robustness. We can now summarize the relationships among all document classes introduced using the Venn diagram in Figure 2. Well-formatted documents form the smallest class (yellow), and are strictly contained within loosely-formatted documents (Definition 4, orange) via Theorem 5. For any approach Infer-SDK Infer-SD_K from K, loose-formattedness is a sufficient condition for SHT robustness (Theorem 6), while SD conformance is both necessary and sufficient (Theorem 1). Consequently, for each Infer-SDK Infer-SD_K, loosely-formatted documents are strictly contained within the class of documents that satisfy SD conformance (one such conformance class is highlighted in green). We also highlight the corresponding conformance classes for local-first (blue) and global-first (purple) approaches, which are two instances of K. Loosely-formatted documents lie in the intersection of these conformance classes. Depth-aligned documents (pink) guarantee robustness under the local-first approach, so they lie within the local-first conformance class, with possible intersections with other classes. Frequency of Each Class. Across 600 real-world documents spanning diverse domains from the source datasets of our evaluation (see Appendix D) with manually annotated true SHTs, we find 60.17% are loosely-formatted, which is 2.57×2.57× the fraction of well-formatted documents (23.39%). To further analyze class frequencies at scale, we additionally collect 3,919 real-world PDF documents (et al.(2021), PI), each with tables of contents encoded in metadata (i.e., extractable via get_toc in PyMuPDF (PyMuPDF, 2025)), avoiding manual true SHT construction. Among them, 52.0% are well formatted, 82.6% loosely formatted, and 32.5% depth-aligned; 85.7% and 83.4% satisfy SD conformance under the local- and global-first approaches, respectively. Since local-first dominates, we focus on it in our evaluation. 4.5. Relationship to ZenDB Lin et al. (Lin et al., 2025b) infer true SHTs for well-formatted documents, which is equivalent to global-first SHED, as is proved in Appendix C. SHED differs from ZenDB in the following ways: • A new problem formulation (Section 2): ZenDB focuses on the true SHT; we formulate robust and compact SHT inference, which is practically useful and more feasible. • A general two-stage framework (Sections 3 and 4): SHED splits SHT inference into two stages, of which ZenDB’s algorithm is just one choice for the first stage, and generalizes global and local-first algorithms into an infinite family of approaches. • Broad applicability (Section 4): SHED extends beyond ZenDB’s narrow class (<<25% of real-world documents in Appendix D) to much broader classes (>>60%), with robustness guarantees. 5. Evaluation Setup We evaluate SHED 44 4 Code available at https://github.com/Ruiying-Ma/SHED on real-world documents, assessing the robustness and compactness of its inferred SHTs and its usefulness in agentic document question answering (QA). Datasets and implementation of SHED are described in Section 5.1 and Section 5.2, respectively. We then present SHT evaluation in Section 6, agentic document QA in Section 7, and scalability analysis in Section 8. 5.1. Datasets Table 1. Statistics of our evaluation datasets. Avg. doc size: average word count per document in each dataset. #Docs (#Qs): number of documents (questions) in each dataset. Statistics Civic Contracts Finance Papers Avg. doc size 7156 7863 178,905 17,352 #Docs (#Qs) 107 248 100 500 Dataset creation. We collected real-world PDF documents spanning diverse lengths, domains, and document templates, with QA sets from existing document QA benchmarks: civic agenda reports from (Lin et al., 2025b; Center, 2024) (Civic), legal contracts from (Koreeda and Manning, 2021b) (Contracts), financial filings from (Islam et al., 2023) (Finance), and scientific papers from (Dasigi et al., 2021) (Papers). Since these original datasets contain either simple documents (e.g., ~2K tokens with shallow, single-level true SHTs) or simple natural-language questions (e.g., answerable from a single sentence in the queried document), they are insufficient for stress-testing our techniques for SHT inference and document QA. We therefore extend our datasets by composing documents. Specifically, for each question q associated with a document D, we replace D with a composite document D′D , constructed by concatenating D with k randomly selected documents from the same dataset (e.g., k=3k=3 for Civic), each preceded by a title page bearing its name. Answering q now requires identifying D, which appears as a section in D′D , making the task more challenging. To construct the true SHTs for each composite document D′D , we first manually construct the SHTs of its constituent documents, and concatenate their roots. We use the modified datasets for evaluation. Dataset statistics are in Table 1 (details in Appendix D), which reports average document size, the number of documents (#Docs), and questions (#Qs) per dataset. Here, #Docs equals #Qs, as each question is associated with a randomly chosen document. Finance has long documents, followed by Papers; Civic and Contracts are shorter. Civic has complex nested structures, while Contract has dense layouts (i.e., short spans between headers). To evaluate how SHED performs on large-scale data, we additionally collect 3 datasets with complex hierarchical structure from different domains (law (Office of the Federal Register, National Archives and Records Administration, 2025), telecom (European Telecommunications Standards Institute, 2026), environment (Federal Energy Regulatory Commission, 2026)) with synthesized questions and manually labeled ground-truth answers, as we will discuss in Section 8. 5.2. SHED Implementation For header identification, we use small pretrained models that can be run on CPUs from Huridocs (HURIDOCS, 2025). Following Huridocs’ recommendations, we use a smaller model (Ke et al., 2017) for large-scale datasets (Finance and Papers), trading slightly lower accuracy for substantially faster execution than the larger model (HURIDOCS, 2025; Da et al., 2023). For each header phrase, we extract its visual pattern using PyMuPDF (PyMuPDF, 2025). The header phrases are treated as nodes V and clustered by their visual patterns, yielding clusters C. Finally, we use local-first SD inference, and construct SHTs T using Algorithm 3. We adopt local- over global-first since more documents satisfy SD conformance under local-first (as shown in prior statistics in Section 4.4), for which local-first infers more robust and compact SHTs (Appendix E.7). We implemented SHED using ~1.3k lines of Python. 6. Evaluation of SHT Inference We evaluate robustness and compactness of SHTs inferred by SHED and five baselines on documents from four datasets. Overall, SHED achieves average F-1 scores 13%–68% higher than non-LLM baselines and 9%–15% higher than significantly more expensive LLM-based approaches under two metrics, demonstrating its advantage in simultaneously ensuring robustness and optimizing compactness. We describe the baselines and metrics in Section 6.1, and present evaluation results in Section 6.2. 6.1. SHT Inference Experimental Setup We compare SHED against five baselines in terms of SHT robustness and compactness using two metrics. 6.1.1. Baselines We have five baselines spanning rule-based, custom model-based, and LLM-based approaches: Deep. This approach uses the same nodes V and clusters C as SHED, and constructs an SHT by linking the header nodes into a list in index order (e.g., 1(d)-1), guaranteeing robustness at the cost of compactness. Wide. Using the same nodes V and clusters C, this approach selects the first node as the root and the remaining nodes as its children (e.g., 1(d)-2), with low robustness and high compactness. GROBID. To infer an SHT for a composite document, this approach infers an SHT for each individual document using a model trained on scientific papers (GROBID, 2025), adds its title as a root node, and merges these individual document SHTs under a single virtual root. Since the model is not applied directly to composite documents, we treat GROBID’s evaluation results as an optimistic upper bound. LLM-text. This approach extracts plain text from D using PyMuPDF and prompts an LLM (GPT-5.4) to infer an SHT from the text in one shot (see prompt in Appendix F.1). LLM-vision. This approach prompts an LLM (GPT-5.4) with page images from D to infer SHTs. Pages are grouped sequentially into batches of 50 pages due to LLM input limits (prompts in Appendix F.1); SHTs inferred per batch are merged under a virtual root. This approach is state-of-the-art among those jointly modeling PDF layout and semantics, inferring better structure than others (, e.g., SmolDocling-256M-preview (Nassar et al., 2025); Appendix E.6). Table 2. Recall, precision, and F-1 scores for identified headers relative to the true headers, averaged per dataset and then across datasets (stratified average Avg.), as well as the total cost (USD) of SHT inference per dataset (Tot.: summed across datasets). SHED, Deep, and Wide use the same set of headers extracted with Huridocs; we report SHED only as the other two are identical on header inference and cost. Green: highest recall, precision, F-1 scores, and lowest cost per dataset Approach Recall Precision F-1 Total Cost (USD) Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Tot. GROBID 0.14 0.21 0.61 0.85 0.45 0.73 0.61 0.58 0.85 0.69 0.24 0.30 0.58 0.84 0.49 0 0 0 0 0 LLM-text 0.91 0.46 0.56 0.86 0.70 0.84 0.80 0.52 0.88 0.76 0.87 0.56 0.48 0.87 0.70 5.7 10.7 104.0 36.3 156.6 LLM-vision 0.91 0.37 0.72 0.85 0.71 0.82 0.73 0.48 0.85 0.72 0.85 0.47 0.55 0.85 0.68 12.0 19.9 88.6 43.4 164.0 SHED 0.93 0.85 0.95 0.92 0.91 0.89 0.93 0.60 0.90 0.83 0.91 0.88 0.72 0.91 0.86 0 0 0 0 0 When analyzing correctness, robustness, and compactness, we assume that the node set V used by SHED is identical to that of the true SHT V′V . This assumption need not hold due to errors in header identification, which we will evaluate and discuss in Section 6.2. 6.1.2. Evaluation Metrics We design two metrics to evaluate robustness and compactness: top-down, denoted M↓M_ , and bottom-up, denoted M↑M_ . Given an inferred SHT T (with header nodes only) for a document with true SHT T′T , M↓M_ compares, for each node v in T′T , the text spans ts(v)ts(v) and ts′(v)ts (v) inferred from T and T′T , respectively, motivated by the definition of robustness (Definition 3), which requires ts′(v)⊆ts(v)ts (v) ts(v). In contrast, M↑M_ operates in reverse: it compares the lists of ancestor headers of v inferred from T and T′T , denoted H(v)H(v) and H′(v)H (v), respectively, motivated by Theorem 5, which requires H′(v)⊆H(v)H (v) H(v). Let the node sets of T and T′T be V and V′V , respectively. As mentioned earlier, V may differ from V′V . We now define the top-down and bottom-up metrics for T. Text-span overlap. Both metrics rely on the text-span overlap ts(v)∩ts′(v)ts(v)∩ ts (v), computed as follows: we normalize ts(v)ts(v) and ts′(v)ts (v) (by canonicalizing characters, removing punctuation, lowercasing, and normalizing whitespace), split each span into whitespace-separated tokens (i.e., a multiset of words), and take the intersection of the two multisets. Text spans include all non-image text (e.g., tables, captions, page headers and footers) but exclude section headers (this has negligible impact since headers are far shorter than the text spans). Long or empty sections are treated like other sections. Top-down (M↓M_ ). Consider a node v∈V′v∈ V . Suppose v∈Vv∈ V; we consider the other case later. M↓M_ compares ts(v)ts(v) (i.e., a set of words) with ts′(v)ts (v) in terms of recall REC(v)=|ts(v)∩ts′(v)||ts′(v)| (v)= |ts(v)∩ ts (v)||ts (v)|, precision PREC(v)=|ts(v)∩ts′(v)||ts(v)| (v)= |ts(v)∩ ts (v)||ts(v)|, and F-1 score F-1(v)=2|ts(v)∩ts′(v)||ts(v)|+|ts′(v)| F-1(v)= 2|ts(v)∩ ts (v)||ts(v)|+|ts (v)|, which respectively measure robustness, compactness, and their trade-off. The overall top-down robustness and compactness of T are computed by averaging over all nodes in V′V : M↓(T)=avgv∈V′f(v)M_ (T)=avg_v∈ V f(v), where f∈REC, PREC, F-1f∈\REC, PREC, F-1\. We average over V′V to ensure that SHTs inferred from the same document by different methods, potentially with different node sets, are evaluated on a common basis. If v∉Vv∉ V, we select the “closest” ancestor node u∈Vu∈ V whose text span ts(u)ts(u) contains v’s header, such that no child of u has a text span that contains v’s header, to compute f(v)f(v). If multiple such nodes u exist (e.g., v is referenced by multiple sections), we choose the one that maximizes f(v)f(v). Bottom-up (M↑M_ ). M↑(T)M_ (T) is computed analogously to M↓(T)M_ (T), except that ts(v)ts(v) (resp. ts′(v)ts (v)) of each node v∈V′v∈ V is replaced by H(v)H(v) (H′(v)H (v)), where H(v)H(v) (H′(v)H (v)) is defined as the list of header phrases corresponding to the nodes in the path from the root to v in T (T′T ), ordered by phrase indices. 6.2. SHT Inference Results We compare SHED with baselines in terms of header identification accuracy, SHT inference cost, and SHT robustness and compactness. Table 3. M↓M_ and M↑M_ results, averaged per dataset and evaluated with f∈REC,PREC,F-1f∈\REC,PREC,F-1\ for recall, precision, and F-1 score, representing robustness, compactness, and their trade-off, respectively. Avg.: stratified averages across datasets. Green: highest per dataset per metric; costs for each scheme can be found in Table 2. Approach Recall (Robustness) Precision (Compactness) F-1 (Trade-off) Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Top-down: M↓(T)=avgv∈T′f(v)M_ (T)=avg_v∈ T f(v), where f(v)f(v) calculates recall, precision, and F-1 score of ts(v)ts(v) relative to ts′(v)ts (v). Deep 0.94 0.99 1.00 0.97 0.98 0.21 0.15 0.09 0.20 0.16 0.29 0.20 0.13 0.27 0.22 Wide 0.70 0.81 0.81 0.78 0.78 0.93 0.90 0.97 0.97 0.94 0.72 0.74 0.81 0.79 0.77 GROBID 0.48 0.84 0.74 0.76 0.71 0.25 0.45 0.75 0.83 0.57 0.26 0.47 0.66 0.76 0.54 LLM-text 0.96 0.93 0.76 0.96 0.90 0.98 0.67 0.61 0.96 0.81 0.96 0.67 0.57 0.95 0.79 LLM-vision 0.97 0.89 0.94 0.95 0.94 0.97 0.61 0.77 0.94 0.82 0.97 0.60 0.73 0.93 0.81 SHED 0.90 0.97 0.94 0.96 0.94 0.91 0.88 0.95 0.95 0.92 0.89 0.87 0.90 0.94 0.90 Bottom-up: M↑(T)=avgv∈T′f(v)M_ (T)=avg_v∈ T f(v), where f(v)f(v) calculates recall, precision, and F-1 score of H(v)H(v) relative to H′(v)H (v). Deep 0.94 0.91 0.98 0.85 0.92 0.28 0.26 0.15 0.33 0.26 0.39 0.28 0.20 0.41 0.32 Wide 0.32 0.41 0.26 0.25 0.31 0.94 0.94 0.98 0.95 0.95 0.46 0.53 0.38 0.34 0.43 GROBID 0.20 0.48 0.37 0.73 0.45 0.38 0.73 0.57 0.91 0.65 0.25 0.52 0.40 0.78 0.49 LLM-text 0.76 0.60 0.40 0.79 0.64 0.71 0.74 0.60 0.94 0.75 0.72 0.62 0.45 0.83 0.66 LLM-vision 0.92 0.47 0.50 0.77 0.67 0.92 0.79 0.80 0.95 0.87 0.91 0.55 0.57 0.82 0.71 SHED 0.92 0.82 0.69 0.82 0.81 0.93 0.92 0.71 0.93 0.87 0.93 0.83 0.65 0.84 0.81 Header identification. As in Table 2, SHED (which uses Huridocs) consistently achieves high accuracy, whereas GROBID performs poorly on datasets Civic, Contracts, and Finance that are outside its training domain. LLM-based approaches perform poorly on Contracts and Finance. For Contracts, which has a dense layout (i.e., short spans between headers), LLMs tend to ignore lower-level headers and focus only on top-level ones, leading to low recall. For Finance, which contains long documents, LLMs lose track of headers midway (Liu et al., 2024a); this issue also occurs, to a lesser extent, in other datasets. Moreover, 0.9% (3.7%) of headers identified by LLM-text (LLM-vision) are hallucinations that do not appear in the document. Cost. Table 2 reports the end-to-end cost of inferring SHTs from a PDF, including preprocessing (i.e., layout parsing and visual pattern extraction) and tree construction. Only LLM-text and LLM-vision incur LLM costs, in total U.S. $157 and $164 across all datasets, respectively, using GPT-5.4. SHED and other baselines incur no LLM cost, because they use open-source pre-trained models and Python programs for these steps. Robustness, compactness, and trade-off. As shown in Table 3, across almost all datasets for both M↓M_ and M↑M_ , Deep (Wide) has the highest values of recall (precision, resply.) among all approaches. Both approaches are closely followed by SHED with minor reductions in recall and precision, whereas the remaining baselines fail to achieve comparable performance. However, both Deep and Wide exhibit low F-1 scores for both M↓M_ and M↑M_ : deep trees have poor compactness (and therefore precision), while wide trees have poor robustness (i.e., recall). GROBID has higher M↓M_ and M↑M_ values of recall, precision, and F-1 scores on Papers than on the other datasets, as Papers closely aligns with its training domain, showing GROBID’s limited generalizability. LLM-vision outperforms LLM-text in average F-1 score in both M↓M_ and M↑M_ , due to the additional visual information that helps LLMs infer structures more accurately. True header ablation. To isolate structure inference from header identification errors, we evaluate SHED with the true headers V′V : this improves average recall, precision, and F-1 by only 3%–6% under both M↓M_ and M↑M_ (see Appendix E.1 for details). Subsequent evaluations therefore use the extracted headers, which perform comparably and reflect the realistic setting where V′V is unavailable. 7. Evaluation of Agentic Question Answering We evaluate agentic document QA under four strategies, two with SHT assistance and two without. Overall, our SHT-based agent achieves the highest average accuracy and lowest cost, improving accuracy by 7% and 19% over two non-SHT strategies, respectively, while reducing cost by 9×9× and 10×10× compared to strategies that process documents (and SHTs) in context. We also evaluate various agentic retrieval baselines, and our SHT-based agent achieves 3%–23% higher accuracy while being 1.3–2× cheaper than others. We further compare SHED against SHT inference baselines using our SHT-based agent. SHED achieves accuracy and cost comparable to true SHTs, while outperforming other SHT inference approaches by 6%–19% in average accuracy, while reducing total cost by up to 9×9×. We describe the four strategies and metrics in Section 7.1, present the strategy evaluation results in Section 7.2, the retrieval ablation results in Section 7.3, and the SHT ablation results in Section 7.4. 7.1. Agentic QA Evaluation Setup 7.1.1. Evaluated Strategies We evaluate four strategies, spanning in-context processing (Li et al., 2024b) and tool-based retrieval (Bigeard et al., 2025), with and without SHT assistance. We use GPT-5.4 as the backbone model. For in-context strategies, a single LLM API call places all information (documents with/without SHTs) in the model context. For tool-based retrieval, we evaluate ReAct-style agents equipped with different retrieval tools (Yao et al., 2022). Here, agents have no direct access to the full document text; instead, at each iteration an agent reasons over the current context, including prior tool calls and their results, and generates a response via an LLM API call (with up to three retries for non-200 status codes), which may contain one or more tool calls. The runtime executes these tool calls and appends their outputs (i.e., retrieved content) to the context for the next iteration. We implement the agents using LangChain (Chase, 2022), capped at 100 iterations. We evaluate the following four strategies, each of which includes the question as part of the prompt, but differ in terms of how much document context and which tools are provided: Vanilla-in-context. This strategy places the full serialized document text (obtained via get_text from PyMuPDF) into the model context, without using SHTs. Vanilla-grep agent. This strategy gives the agent a grep tool that takes a regex pattern and returns matching document chunks, each containing one match with 1000 characters of context. Results are streamed across calls: for a pattern, the first call returns the earliest match in reading order and subsequent calls successive matches. If the pattern changes, the search restarts from the beginning; if a previous pattern is reused after other patterns, the tool resumes from its last returned position. The agent decides when to stop searching a pattern. SHT-augmented-context. This strategy augments model context with the true SHT corresponding to the document prepended to the document text, listing section headers one per line in reading order. Each line begins with a numeric prefix indicating the section’s hierarchical level, followed by a separator | and the section header (e.g., “3.1 | Consolidated Statements of Income”). SHT-based agent. This strategy provides an agent with the true SHT for the document in-context (via the user prompt, formatted as in the previous strategy). The agent reasons over the SHT and uses a read_section tool that takes a section’s numeric prefix and returns the corresponding section content (i.e., text span). 7.1.2. Evaluation Metrics We use task-specific metrics to evaluate the above strategies. For Civic questions that ask for a set of civic projects, we use F-1 score. For Contracts questions with a single true answer drawn from a fixed-size set, we use 0-1 accuracy. For Finance and Papers, which involve free-form or open-ended answers, we use LLM-as-judge (Zheng et al., 2023) with GPT-4o-mini, following established practice (Schimanski et al., 2026; Zhao et al., 2026; Wang et al., 2025a; Yepes et al., 2024) (prompts in Appendix F.2). We report the total cost of end-to-end SHT inference and QA. 7.2. Usefulness of SHTs We report average accuracy and total cost in Table 4. Accuracy. Overall, SHTs improve accuracy over non-SHT strategies: SHT-augmented-context outperforms vanilla-in-context by 7%, and the SHT-based agent by 19% over vanilla-grep. Using SHTs does not provide any gains for Contracts and Papers (SHT-augmented-context vs. vanilla-in-context), while the SHT-based agent improves accuracy by 30% on Contracts and 23% on Papers over vanilla-grep, likely because full document provides enough context that enables LLMs to infer hierarchical structure. With SHT assistance, the SHT-based agent has 6% lower accuracy than SHT-augmented-context on Civic because the questions require cross-section aggregation; the agent misses correct answers by checking only relevant sections in isolation. In contrast, the agent achieves 5% higher accuracy on Contracts because the questions require reasoning over multiple sections but without cross-section dependencies, making SHT-augmented-context more prone to context rot (Hong et al., 2025) when all sections are processed in one shot. Cost. The SHT-based agent is overall 10×10× and 9×9× cheaper than SHT-augmented-context and vanilla-in-context, respectively, especially on the large-scale Finance setting (30×30× and 29×29×), because the agent loads only small relevant sections. Compared with vanilla-grep, the SHT-based agent is overall 1.3×1.3× cheaper, because SHTs provide additional semantics that enable more precise retrieval than keyword search (grep). On Finance, the SHT-based agent has higher cost than vanilla-grep, because section-based retrieval (read_section) often returns more content than 1k-character chunks (grep), especially in long documents, while also providing 8% higher accuracy. Table 4. Average accuracy and total cost (USD, inside parenthesis) of four strategies by dataset. The last column reports stratified average accuracy (Avg.) and total cost (Tot.) across four datasets. Green: highest accuracy (lowest cost) per dataset. Strategy Civic Contracts Finance Papers Avg. (Tot.) Vanilla-in-context 0.59 (3.1) 0.71 (6.7) 0.64 (112.5) 0.77 (32.6) 0.67 (154.9) Vanilla-grep agent 0.57 (3.4) 0.45 (4.9) 0.63 (2.3) 0.53 (11.9) 0.55 (22.5) SHT-aug-context 0.78 (4.1) 0.70 (9.0) 0.71 (118.2) 0.77 (34.1) 0.74 (165.3) SHT-based agent 0.72 (2.1) 0.75 (5.1) 0.71 (3.9) 0.76 (6.3) 0.74 (17.4) 7.3. Agentic Retrieval Ablation The SHT-based agent outperforms vanilla-grep, benefiting from both structure and a different retrieval tool (i.e., read_section). To isolate the two, we evaluate SHT-grep that uses grep with SHTs and two embedding-based agents, vanilla-embed and SHT-embed. Setup. The SHT-grep and SHT-embed agents have true SHT provided in the user prompt (as in SHT-based agent). For both embedding baselines, we split each document into 1,000-character chunks (as in vanilla-grep) and embed them with the text-embedding-3-small model; the retrieval tool takes a natural-language query and returns chunks by descending cosine similarity, one-by-one. Results. Table 5 reports accuracy and cost of all agents. SHTs improve accuracy for both retrieval tools: SHT-grep (SHT-embed) outperforms vanilla-grep (vanilla-embed) by 2–25% (6–35%). The SHT-based agent is the best-performing one—3%–23% more accurate and 1.3–2× cheaper than all agentic baselines. Table 5. Average accuracy and total cost in parenthesis of all agents: baselines (vanilla-grep from Tab. 4, and the 3 other approaches from Sec. 7.3) and SHT-based (Tab. 4). Green: highest acc. (lowest cost). Agent Civic Contracts Finance Papers Avg. Acc. (Tot. Cost) Vanilla-embed 0.38 (4.5) 0.39 (8.5) 0.64 (2.6) 0.64 (9.1) 0.51 (24.7) Vanilla-grep 0.57 (3.4) 0.45 (4.9) 0.63 (2.3) 0.53 (11.9) 0.55 (22.5) SHT-grep 0.62 (5.5) 0.70 (12.5) 0.65 (5.6) 0.61 (11.3) 0.65 (34.8) SHT-embed 0.75 (4.9) 0.74 (15.2) 0.64 (5.8) 0.69 (9.2) 0.71 (35.0) SHT-based 0.72 (2.1) 0.75 (5.1) 0.71 (3.9) 0.76 (6.3) 0.74 (17.4) 7.4. SHT Ablation Figure 7. Total cost (USD) vs. average accuracy of SHT-based agents using different SHTs across datasets. Table 6. Average accuracy and total cost (USD, inside parenthesis) of SHT-based agents using different SHTs by dataset. The last column reports stratified average accuracy (Avg.) and total cost (Tot.) across four datasets. Green: highest accuracy (lowest cost) per dataset. Civic Contracts Finance Papers Avg. (Tot.) Deep 0.59 (12.2) 0.63 (27.1) 0.20 (95.5) 0.75 (39.7) 0.54 (174.5) Wide 0.57 (2.0) 0.61 (4.9) 0.67 (3.0) 0.76 (5.3) 0.65 (15.1) GROBID 0.31 (1.3) 0.70 (5.8) 0.63 (5.0) 0.74 (5.3) 0.60 (17.4) LLM-text 0.68 (7.9) 0.60 (15.9) 0.59 (108.4) 0.74 (40.4) 0.65 (172.6) LLM-vision 0.75 (14.0) 0.50 (25.0) 0.69 (93.3) 0.74 (47.9) 0.67 (180.3) SHED 0.67 (2.2) 0.74 (6.4) 0.75 (5.4) 0.75 (6.2) 0.73 (20.1) So far, we have shown that SHTs improve QA performance. We now evaluate different SHT inference approaches (Section 6.1) on document QA. We focus on the SHT-based agent for this comparison, as it achieves the best overall performance (accuracy and cost) among all strategies. Overall, we find that SHED achieves the highest average accuracy and lowest total cost among all SHT inference approaches, performing comparably to using true SHTs (Figure 7). Per-dataset results are in Table 6. Accuracy. SHED outperforms Deep by 19%, GROBID by 13%, Wide and LLM-text by 8%, and LLM-vision by 6% in average accuracy. Deep performs poorly due to low compactness causing context rot, especially on Finance, where the agent frequently exceeds the model context limit. Wide achieves low accuracy due to poor robustness: when the agent retrieves a section, it only retrieves its prefix, and may miss the content of subsections appended as siblings of that section in the tree. GROBID performs worse on out-of-domain datasets than on Papers, indicating limited generalizability. LLM-based approaches lack guarantees on robustness or compactness, especially on Contracts with dense layout and on large-scale Finance documents. All approaches have similar accuracy on Papers, as it is trivial to infer structure only from section headers based on domain knowledge carried by the model. Cost. SHED has cost comparable to Wide and GROBID: Wide is the cheapest due to strong compactness, as each header contains only a small text span (ending at the next header), at the cost of lower robustness, leading to 8% lower accuracy than SHED; GROBID is cheap because its SHTs contain inaccurate headers (low F-1 scores in Table 2), resulting in 13% lower accuracy than SHED. SHED achieves both low cost and high accuracy through effective header identification and strong robustness-compactness guarantees. Deep has poor compactness, with each header’s text span extending to the end of the document, resulting in 4×4×–18×18× higher cost than SHED and up to 55% accuracy drop across datasets due to context rot or exceeding the context limit. For LLM-text and LLM-vision, SHT inference dominates across datasets (67%–96% for LLM-text and 80%–95% for LLM-vision), making them both about 9×9× more expensive than SHED, while still yielding 8% and 6% lower average accuracy due to lack of robustness and compactness guarantees. 8. Scalability Analysis To show SHED’s scalability, we estimate the SHT inference latency of SHED (Section 8.1), and repeat SHT inference and QA evaluations from Sections 6 & 7 on large-scale data, varying composition sizes (Section 8.2) and evaluating 3 new datasets of individually complex documents (Section 8.3). 8.1. SHT Inference Latency We evaluate SHED’s SHT inference latency on 80 sampled documents (20 per dataset; Table 1) and extrapolate to all 955 documents. SHED is estimated to sequentially process all documents (~54K pages, 30M tokens) in 5 hours, showing good scalability; using parallelization would further reduce latency. GROBID takes 4 hours but infers poor SHTs, LLM-based approaches take 2–5 hours but are costly, and SmolDocling-256M-preview is slow, taking ~11.4 days. Details of the testbed, results, and discussion are in Appendix E.5. 8.2. Document Composition So far we used composite documents, each concatenating a queried original with k others, i.e., composition size k+1k+1 (k varies by dataset; e.g., k=3k=3 for Civic; details in Appendix D). We now vary composition size from 1 (single originals) to 2(k+1)2(k+1), mirroring growing document size and structural complexity. Across all sizes, SHT-based agent with SHED is accurate (0.71—0.73 on avgerage) at low cost ($12–$28 total, up to 28×28× cheaper than baselines), on par with true SHTs (0.71—0.74, $11–$25). Its gains widen with size: it is up to 7% to 19% to 27% more accurate than the baselines at sizes 1, k+1k+1, and 2(k+1)2(k+1); its cost rises only 1.4× as size doubles. We provide detailed results and analysis in Appendix E.3. 8.3. Complex Documents with Synthetic Q&A To further show SHED’s usefulness, we collected 3 new datasets with 119 complex documents and 142 synthetic Q&A pairs. Specifically, we collected CFR (Office of the Federal Register, National Archives and Records Administration, 2025) (30 federal regulation codes), ETSI (European Telecommunications Standards Institute, 2026) (49 radio-equipment standards), and FERC (Federal Energy Regulatory Commission, 2026) (40 environmental assessments), averaging 415K, 30K, and 49K tokens per document. For each dataset, we designed realistic query templates, instantiated 1–2 queries per document, and manually labeled ground-truth answers. We evaluate SHT-based agent with SHED against Wide and two non-SHT strategies, vanilla-in-context and vanilla-grep. Due to budget limits, we omit SHT-aug-context, which is as accurate as SHT-based agent with SHED but far costlier (Section 7.2), and other SHT baselines, which are less accurate or costlier than Wide (Section 7.4). Overall, SHED has 7%–18% higher QA average accuracy at up to 15×15× lower cost than baselines. Details can be found in Appendix E.4. 9. Related Work We survey related work on document processing and analytics. Systems for Document Analytics. Recent systems target document processing for analytical tasks. Some systems focus on table extraction for predominantly tabular or structured documents (Wu et al., 2022; Lin et al., 2025a; Arora et al., 2023), which could complement our work. Other systems provide declarative interfaces for general-purpose document processing (Liu et al., 2024b; Patel et al., 2025; Shankar et al., 2024; Urban and Binnig, 2024; Jo and Trummer, 2023; Sun et al., 2025a; Sun et al., 2025c) by treating documents as linear text sequences and ignoring their inherent structure; our approach can be integrated to enhance their capabilities. ZenDB (Lin et al., 2025b) is the only document analytics system that considers structure, focusing on the setting where many documents in a collection share the same template. Our approach broadens its applicability with a new formulation of structure extraction and a general two-stage framework. Document Structure Inference. Significant prior work has considered document structure inference. Some approaches target documents with explicit structures, such as HTML (Manabe and Tajima, 2015), which don’t translate to PDF and Word documents. For the latter class of documents, existing approaches fall into three classes. Rule-based approaches rely on heuristics (Fenniak et al., 2024; Singer-Vine and The pdfplumber contributors, 2025; PyMuPDF, 2025; pdfminer.six, 2019; pdfium, 2025), which often fail on heterogeneous layouts and provide no guarantees, being largely outperformed by LLM-based approaches. Our approach instead provides robustness guarantees sufficient for real-world applications. Learning-based approaches (Koreeda and Manning, 2021a; Wang et al., 2024; Ma et al., 2023; Blecher et al., 2023) train models to infer structures but generalize poorly. We choose GROBID (GROBID, 2025), trained primarily on scientific papers due to its wide adoption. Our approach differs by leveraging learning-based approaches only for header identification, a simpler task (Zhong et al., 2019; Pfitzmann et al., 2022; Li et al., 2020), where models achieve high accuracy (Da et al., 2023; HURIDOCS, 2025; Ke et al., 2017). Finally, LLM-based approaches can infer structures from plain text (Li et al., 2024a; Wang et al., 2025b) or page images (ContextGem, 2025; LlamaParse, 2025). As we see in our experiments, these approaches are costly, hallucination-prone (Huang et al., 2025; Bubeck et al., 2023; Liu et al., 2024a), and yield poor robustness and compactness. Agentic Document Processing. Agents process documents across domains such as coding (Anthropic, 2025b; OpenAI, 2025), finance (Bigeard et al., 2025), and scientific research (Starace et al., 2025), treating documents as bags of words by directly processing the full document (Islam et al., 2023) or via retrieval for relevant portions (Sun et al., 2025b; Singh et al., 2025). They ignore the hierarchical structure in documents that is crucial for accuracy and cost, as shown by augmenting agents with SHED. Related settings include agent skills (Anthropic, 2025a) and knowledge management systems (e.g., LLM wikis (Karpathy, 2026)), where agents operate over hierarchically organized document collections rather than a single document. This hierarchical organization enables agents to progressively load relevant components, improving accuracy and reducing cost (Nielsen, 2006). For instance, agent skills require users to manually define and maintain task-specific hierarchies; SHED can potentially be used here to recover hierarchical structures without manual specification. Retrieval-Augmented Generation (RAG). RAG retrieves the most relevant context for generation, compensating for LLM limitations on long documents. Most techniques treat a document as a collection of chunks (Lewis et al., 2020; Izacard and Grave, 2020; Singh et al., 2025), a recursive tree of summaries (Sarthi et al., 2024), or a knowledge graph (Edge et al., 2024; Jimenez Gutierrez et al., 2024), ignoring inherent hierarchical structure as in SHED. Our technique could be used by such approaches to improve RAG. Other RAG techniques leverage hierarchical structures (Wang et al., 2025b; Zhang et al., 2025; Li et al., 2024a) but infer them using LLMs at significantly higher cost and lacking guarantees. 10. Conclusion We introduced SHED, a two-stage workflow for SHT inference that guarantees robustness with good compactness. We proposed local- or global-first SD inference, and generalized them into an infinite family of approaches. We further theoretically characterized a taxonomy of document classes for which SHED generates robust SHTs for each approach. Empirically, SHED outperforms non-LLM and expensive LLM-based SHT inference baselines by 13%–68% and 9%–15% in F-1 scores, respectively, at no cost. Applying SHED to agentic document QA improves accuracy by 3%–23% over baselines, reducing cost by up to 10×10×. References Agents (2025) Improving Agents. 2025. Which Table Format Do LLMs Understand Best? https://w.improvingagents.com/blog/best-input-data-format-for-llms/ Anthropic (2025a) Anthropic. 2025a. Agent Skills. Retrieved April 13, 2026 from https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview Anthropic (2025b) Anthropic. 2025b. Claude Code. Retrieved April 13, 2026 from https://code.claude.com/docs/en/overview Anthropic (2026) Anthropic. 2026. Claude Cowork. Retrieved April 13, 2026 from https://claude.com/product/cowork Arora et al. (2023) Simran Arora, Brandon Yang, Sabri Eyuboglu, Avanika Narayan, Andrew Hojel, Immanuel Trummer, and Christopher Ré. 2023. Language models enable simple systems for generating structured views of heterogeneous data lakes. arXiv preprint arXiv:2304.09433 (2023). Bigeard et al. (2025) Antoine Bigeard, Langston Nashold, Rayan Krishnan, and Shirley Wu. 2025. Finance agent benchmark: Benchmarking llms on real-world financial research tasks. arXiv preprint arXiv:2508.00828 (2025). Blecher et al. (2023) Lukas Blecher, Guillem Cucurull, Thomas Scialom, and Robert Stojnic. 2023. Nougat: Neural optical understanding for academic documents. arXiv preprint arXiv:2308.13418 (2023). Bubeck et al. (2023) Sébastien Bubeck, Varun Chandrasekaran, Ronen Eldan, Johannes Gehrke, Eric Horvitz, Ece Kamar, Peter Lee, Yin Tat Lee, Yuanzhi Li, Scott Lundberg, et al. 2023. Sparks of artificial general intelligence: early experiments with GPT-4 (2023). arXiv preprint arXiv:2303.12712 1 (2023). Center (2024) Malibu Agenda Center. 2024. https://w.malibucity.org/AgendaCenter Chase (2022) Harrison Chase. 2022. LangChain. Retrieved April 10, 2026 from https://github.com/langchain-ai/langchain Che et al. (2024) Tian-Yi Che, Xian-Ling Mao, Tian Lan, and Heyan Huang. 2024. A hierarchical context augmentation method to improve retrieval-augmented llms on scientific papers. In Proceedings of the 30th ACM SIGKDD Conference on Knowledge Discovery and Data Mining. 243–254. Chung (2000) Jenny SL Chung. 2000. Signals and reading comprehension—Theory and practice. System 28, 2 (2000), 247–259. ContextGem (2025) ContextGem. 2025. https://github.com/shcherbak-ai/contextgem Da et al. (2023) Cheng Da, Chuwei Luo, Qi Zheng, and Cong Yao. 2023. Vision grid transformer for document layout analysis. In Proceedings of the IEEE/CVF international conference on computer vision. 19462–19472. Dasigi et al. (2021) Pradeep Dasigi, Kyle Lo, Iz Beltagy, Arman Cohan, Noah A Smith, and Matt Gardner. 2021. A dataset of information-seeking questions and answers anchored in research papers. arXiv preprint arXiv:2105.03011 (2021). Ebbers et al. (2022) Tom Ebbers, Rudolf B Kool, Ludi E Smeele, Richard Dirven, Chrisje A den Besten, Luc HE Karssemakers, Tim Verhoeven, Jasmijn M Herruer, Guido B van den Broek, and Robert P Takes. 2022. The impact of structured and standardized documentation on documentation quality; a multicenter, retrospective study. Journal of Medical Systems 46, 7 (2022), 46. Edge et al. (2024) Darren Edge, Ha Trinh, Newman Cheng, Joshua Bradley, Alex Chao, Apurva Mody, Steven Truitt, Dasha Metropolitansky, Robert Osazuwa Ness, and Jonathan Larson. 2024. From local to global: A graph rag approach to query-focused summarization. arXiv preprint arXiv:2404.16130 (2024). European Telecommunications Standards Institute (2026) European Telecommunications Standards Institute. 2026. ETSI European Standards (EN) Deliverables. Retrieved 2026-07-23 from https://w.etsi.org/standards/get-standards Federal Energy Regulatory Commission (2026) Federal Energy Regulatory Commission. 2026. Environmental Assessments and Environmental Impact Statements, FERC eLibrary. Retrieved 2026-07-23 from https://elibrary.ferc.gov/ Fenniak et al. (2024) Mathieu Fenniak, Matthew Stamy, pubpub z, Martin Thoma, Matthew Peveler, exiledkingcc, and pypdf Contributors. 2024. The pypdf library. https://pypi.org/project/pypdf/ GROBID (2025) GROBID. 2008–2025. https://github.com/kermitt2/grobid. arXiv:1:dir:dab86b296e3c3216e2241968f0d63b68e8209d3c Harbert (2021) Tam Harbert. 2021. https://mitsloan.mit.edu/ideas-made-to-matter/tapping-power-unstructured-data Hong et al. (2025) Kelly Hong, Anton Troynikov, and Jeff Huber. 2025. Context Rot: How Increasing Input Tokens Impacts LLM Performance. Retrieved April 13, 2026 from https://w.trychroma.com/research/context-rot Huang et al. (2025) Lei Huang, Weijiang Yu, Weitao Ma, Weihong Zhong, Zhangyin Feng, Haotian Wang, Qianglong Chen, Weihua Peng, Xiaocheng Feng, Bing Qin, et al. 2025. A survey on hallucination in large language models: Principles, taxonomy, challenges, and open questions. ACM Transactions on Information Systems 43, 2 (2025), 1–55. Huang et al. (2022) Yupan Huang et al. 2022. Layoutlmv3: Pre-training for document ai with unified text and image masking. In M. 4083–4091. HURIDOCS (2025) HURIDOCS. 2025. https://github.com/huridocs/pdf-document-layout-analysis Islam et al. (2023) Pranab Islam, Anand Kannappan, Douwe Kiela, Rebecca Qian, Nino Scherrer, and Bertie Vidgen. 2023. Financebench: A new benchmark for financial question answering. arXiv preprint arXiv:2311.11944 (2023). Izacard and Grave (2020) Gautier Izacard and Edouard Grave. 2020. Distilling knowledge from reader to retriever for question answering. arXiv preprint arXiv:2012.04584 (2020). Jimenez Gutierrez et al. (2024) Bernal Jimenez Gutierrez, Yiheng Shu, Yu Gu, Michihiro Yasunaga, and Yu Su. 2024. Hipporag: Neurobiologically inspired long-term memory for large language models. Advances in Neural Information Processing Systems 37 (2024), 59532–59569. Jo and Trummer (2023) Saehan Jo and Immanuel Trummer. 2023. Demonstration of thalamusdb: answering complex sql queries with natural language predicates on multi-modal data. In Companion of the 2023 International Conference on Management of Data. 179–182. Karpathy (2026) Andrej Karpathy. 2026. LLM Wiki. Retrieved April 13, 2026 from https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f Ke et al. (2017) Guolin Ke, Qi Meng, Thomas Finley, Taifeng Wang, Wei Chen, Weidong Ma, Qiwei Ye, and Tie-Yan Liu. 2017. Lightgbm: A highly efficient gradient boosting decision tree. Advances in neural information processing systems 30 (2017). Koreeda and Manning (2021a) Yuta Koreeda and Christopher D Manning. 2021a. Capturing logical structure of visually structured documents with multimodal transition parser. arXiv preprint arXiv:2105.00150 (2021). Koreeda and Manning (2021b) Yuta Koreeda and Christopher D Manning. 2021b. ContractNLI: A dataset for document-level natural language inference for contracts. arXiv preprint arXiv:2110.01799 (2021). Lemarié et al. (2012) Julie Lemarié, Robert F Lorch Jr, and Marie-Paule Péry-Woodley. 2012. Understanding how headings influence text processing. Discours. Revue de linguistique, psycholinguistique et informatique. A journal of linguistics, psycholinguistics and computational linguistics 10 (2012). Lewis et al. (2020) Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, et al. 2020. Retrieval-augmented generation for knowledge-intensive nlp tasks. Advances in neural information processing systems 33 (2020), 9459–9474. Li et al. (2020) Minghao Li, Yiheng Xu, Lei Cui, Shaohan Huang, Furu Wei, Zhoujun Li, and Ming Zhou. 2020. Docbank: A benchmark dataset for document layout analysis. arXiv preprint arXiv:2006.01038 (2020). Li et al. (2024a) Zhuoqun Li, Xuanang Chen, Haiyang Yu, Hongyu Lin, Yaojie Lu, Qiaoyu Tang, Fei Huang, Xianpei Han, Le Sun, and Yongbin Li. 2024a. Structrag: Boosting knowledge intensive reasoning of llms via inference-time hybrid information structurization. arXiv preprint arXiv:2410.08815 (2024). Li et al. (2024b) Zhuowan Li, Cheng Li, Mingyang Zhang, Qiaozhu Mei, and Michael Bendersky. 2024b. Retrieval augmented generation or long-context llms? a comprehensive study and hybrid approach. arXiv preprint arXiv:2407.16833 (2024). Lin et al. (2025a) Yiming Lin, Mawil Hasan, Rohan Kosalge, Alvin Cheung, and Aditya G Parameswaran. 2025a. Twix: Automatically reconstructing structured data from templatized documents. arXiv preprint arXiv:2501.06659 (2025). Lin et al. (2025b) Yiming Lin, Madelon Hulsebos, Ruiying Ma, Shreya Shankar, Sepanta Zeighami, Aditya G Parameswaran, and Eugene Wu. 2025b. Querying templatized document collections with large language models. In 2025 IEEE 41st International Conference on Data Engineering (ICDE). IEEE, 2422–2435. Liu et al. (2024b) Chunwei Liu, Matthew Russo, Michael Cafarella, Lei Cao, Peter Baille Chen, Zui Chen, Michael Franklin, Tim Kraska, Samuel Madden, and Gerardo Vitagliano. 2024b. A declarative system for optimizing ai workloads. arXiv preprint arXiv:2405.14696 (2024). Liu et al. (2024a) Nelson F Liu, Kevin Lin, John Hewitt, Ashwin Paranjape, Michele Bevilacqua, Fabio Petroni, and Percy Liang. 2024a. Lost in the middle: How language models use long contexts. Transactions of the association for computational linguistics 12 (2024), 157–173. LlamaParse (2025) LlamaParse. 2025. https://developers.llamaindex.ai/python/cloud/llamaparse/ LLM-Stats (2026) LLM-Stats. 2026. DocVQA Benchmark Leaderboard. Ma et al. (2023) Jiefeng Ma, Jun Du, Pengfei Hu, Zhenrong Zhang, Jianshu Zhang, Huihui Zhu, and Cong Liu. 2023. Hrdoc: Dataset and baseline method toward hierarchical reconstruction of document structures. In Proceedings of the AAAI Conference on Artificial Intelligence, Vol. 37. 1870–1877. Manabe and Tajima (2015) Tomohiro Manabe and Keishi Tajima. 2015. Extracting logical hierarchical structure of HTML documents based on headings. Proceedings of the VLDB Endowment 8, 12 (2015), 1606–1617. McDowell (2023) Steve McDowell. 2023. https://w.forbes.com/sites/stevemcdowell/2023/03/09/komprise-unleashes-fresh-insights-about-your-unstructured-data/?sh=5f444c474a9 Nassar et al. (2025) Ahmed Nassar et al. 2025. SmolDocling: An ultra-compact vision-language model for end-to-end multi-modal document conversion. In ICCV. 21972–21983. Nielsen (2006) Jakob Nielsen. 2006. Progressive Disclosure. Retrieved April 13, 2026 from https://w.nngroup.com/articles/progressive-disclosure/ Niu et al. (2025) Junbo Niu, Zheng Liu, Zhuangcheng Gu, Bin Wang, Linke Ouyang, Zhiyuan Zhao, Tao Chu, Tianyao He, Fan Wu, Qintong Zhang, et al. 2025. Mineru2. 5: A decoupled vision-language model for efficient high-resolution document parsing. arXiv preprint arXiv:2509.22186 (2025). Office of the Federal Register, National Archives and Records Administration (2025) Office of the Federal Register, National Archives and Records Administration. 2025. Code of Federal Regulations, Annual Editions 2023–2025. Retrieved 2026-07-23 from https://w.govinfo.gov/app/collection/cfr OpenAI (2025) OpenAI. 2025. Codex. Retrieved April 13, 2026 from https://openai.com/codex/ Patel et al. (2025) Liana Patel, Siddharth Jha, Melissa Pan, Harshit Gupta, Parth Asawa, Carlos Guestrin, and Matei Zaharia. 2025. Semantic Operators and Their Optimization: Enabling LLM-Based Data Processing with Accuracy Guarantees in LOTUS. Proceedings of the VLDB Endowment 18, 11 (2025), 4171–4184. pdfium (2025) pdfium. 2025. https://github.com/chromium/pdfium pdfminer.six (2019) pdfminer.six. 2019. https://pdfminersix.readthedocs.io/en/latest/ Petherbridge and Cotropia (2016) Lee Petherbridge and Christopher A Cotropia. 2016. Should Your Law Review Article Have an Abstract and Table of Contents: An Empirical Analysis. Miss. LJ 85 (2016), 295. Pfitzmann et al. (2022) Birgit Pfitzmann, Christoph Auer, Michele Dolfi, Ahmed S Nassar, and Peter Staar. 2022. Doclaynet: A large human-annotated dataset for document-layout segmentation. In Proceedings of the 28th ACM SIGKDD conference on knowledge discovery and data mining. 3743–3751. (60) Chris Mattmann (PI), Wayne Burke, Dustin Graf, Tim Allison, Ryan Stonebraker, Mike Milano, Philip Southam, Anastasia Menshikova, and Peter Wyatt. 2021. SAFEDOCS (C-MAIN-2021-31-PDF-UNTRUNCATED). https://digitalcorpora.org/corpora/file-corpora/c-main-2021-31-pdf-untruncated/ PyMuPDF (2025) PyMuPDF. 2025. https://github.com/pymupdf/PyMuPDF Sarthi et al. (2024) Parth Sarthi, Salman Abdullah, Aditi Tuli, Shubh Khanna, Anna Goldie, and Christopher D Manning. 2024. Raptor: Recursive abstractive processing for tree-organized retrieval. In The Twelfth International Conference on Learning Representations. Schimanski et al. (2026) Tobias Schimanski, Imene Kolli, Jingwei Ni, Yu Fan, Ario Saeid Vaghefi, Elliott Ash, and Markus Leippold. 2026. pdfQA: Diverse, Challenging, and Realistic Question Answering over PDFs. arXiv preprint arXiv:2601.02285 (2026). Shankar et al. (2024) Shreya Shankar, Tristan Chambers, Tarak Shah, Aditya G Parameswaran, and Eugene Wu. 2024. Docetl: Agentic query rewriting and evaluation for complex document processing. arXiv preprint arXiv:2410.12189 (2024). Singer-Vine and The pdfplumber contributors (2025) Jeremy Singer-Vine and The pdfplumber contributors. 2025. pdfplumber. https://github.com/jsvine/pdfplumber Singh et al. (2025) Aditi Singh, Abul Ehtesham, Saket Kumar, and Tala Talaei Khoei. 2025. Agentic retrieval-augmented generation: A survey on agentic rag. arXiv preprint arXiv:2501.09136 (2025). Starace et al. (2025) Giulio Starace, Oliver Jaffe, Dane Sherburn, James Aung, Jun Shern Chan, Leon Maksin, Rachel Dias, Evan Mays, Benjamin Kinsella, Wyatt Thompson, et al. 2025. Paperbench: Evaluating ai’s ability to replicate ai research, 2025. URL https://arxiv. org/abs/2504.01848 (2025). Sui et al. (2024) Yuan Sui, Mengyu Zhou, Mingjie Zhou, Shi Han, and Dongmei Zhang. 2024. Table meets llm: Can large language models understand structured table data? a benchmark and empirical study. In Proceedings of the 17th ACM International Conference on Web Search and Data Mining. 645–654. Sun et al. (2025c) Ji Sun, Guoliang Li, Peiyao Zhou, Yihui Ma, Jingzhe Xu, and Yuan Li. 2025c. Agenticdata: An agentic data analytics system for heterogeneous data. arXiv preprint arXiv:2508.05002 (2025). Sun et al. (2025b) Li Sun, Liu He, Shuyue Jia, Yangfan He, and Chenyu You. 2025b. Docagent: An agentic framework for multi-modal long-context document understanding. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing. 17712–17727. Sun et al. (2025a) Zhaoze Sun, Qiyan Deng, Chengliang Chai, Kaisen Jin, Xinyu Guo, Han Han, Ye Yuan, Guoren Wang, and Lei Cao. 2025a. Quest: Query optimization in unstructured document analysis. arXiv preprint arXiv:2507.06515 (2025). Swoopes et al. (2025) Chelse Swoopes, Ziwei Gu, and Elena L Glassman. 2025. Interface Design to Support Legal Reading and Writing: Insights from Interviews with Legal Experts. arXiv preprint arXiv:2509.24854 (2025). Urban and Binnig (2024) Matthias Urban and Carsten Binnig. 2024. Demonstrating CAESURA: language models as multi-modal query planners. In Companion of the 2024 International Conference on Management of Data. 472–475. U.S. Department of Energy, Office of Scientific and Technical Information (2025) U.S. Department of Energy, Office of Scientific and Technical Information. 2025. OSTI.GOV FAQs. U.S. National Library of Medicine (2025) U.S. National Library of Medicine. 2025. ClinicalTrials.gov: A 25-Year Journey to a Half-Million Registered Studies. Wang et al. (2024) Jiawei Wang, Kai Hu, Zhuoyao Zhong, Lei Sun, and Qiang Huo. 2024. Detect-order-construct: A tree construction based approach for hierarchical document structure analysis. Pattern Recognition 156 (2024), 110836. Wang et al. (2025b) Shu Wang, Yingli Zhou, and Yixiang Fang. 2025b. BookRAG: A Hierarchical Structure-aware Index-based Approach for Retrieval-Augmented Generation on Complex Documents. arXiv preprint arXiv:2512.03413 (2025). Wang et al. (2025a) Xinyu Wang, Jijun Chi, Zhenghan Tai, Tung Sum Thomas Kwok, Hailin He, Zhuhong Li, Yuchen Hua, Muzhi Li, Peng Lu, Suyucheng Wang, et al. 2025a. Finsage: A multi-aspect rag system for financial filings question answering. In Proceedings of the 34th ACM International Conference on Information and Knowledge Management. 6144–6152. Wikipedia (2025) Wikipedia. 2025. EDGAR: Electronic Data Gathering, Analysis, and Retrieval. Wu et al. (2022) Xueqing Wu, Jiacheng Zhang, and Hang Li. 2022. Text-to-table: A new way of information extraction. In Proceedings of the 60th annual meeting of the association for computational linguistics (volume 1: long papers). 2518–2533. Yao et al. (2022) Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik R Narasimhan, and Yuan Cao. 2022. React: Synergizing reasoning and acting in language models. In The eleventh international conference on learning representations. Yepes et al. (2024) Antonio Jimeno Yepes, Yao You, Jan Milczek, Sebastian Laverde, and Renyu Li. 2024. Financial report chunking for effective retrieval augmented generation. arXiv preprint arXiv:2402.05131 (2024). Zhang et al. (2025) Mingtian Zhang, Yu Tang, and PageIndex Team. 2025. PageIndex: Next-Generation Vectorless, Reasoning-based RAG. PageIndex Blog (September 2025). https://pageindex.ai/blog/pageindex-intro. Zhang et al. ([n. d.]) Q Zhang, VSJ Huang, B Wang, J Zhang, Z Wang, H Liang, S Wang, M Lin, C He, and W Zhang. [n. d.]. Document parsing unveiled: Techniques, challenges, and prospects for structured information extraction. arXiv 2024. arXiv preprint arXiv:2410.21169 ([n. d.]). Zhao et al. (2026) Yibo Zhao, Jiapeng Zhu, Zichen Ding, and Xiang Li. 2026. GRACE: Reinforcement Learning for Grounded Response and Abstention under Contextual Evidence. arXiv preprint arXiv:2601.04525 (2026). Zheng et al. (2023) Lianmin Zheng, Wei-Lin Chiang, Ying Sheng, Siyuan Zhuang, Zhanghao Wu, Yonghao Zhuang, Zi Lin, Zhuohan Li, Dacheng Li, Eric Xing, et al. 2023. Judging llm-as-a-judge with mt-bench and chatbot arena. Advances in neural information processing systems 36 (2023), 46595–46623. Zhong et al. (2019) Xu Zhong, Jianbin Tang, and Antonio Jimeno Yepes. 2019. Publaynet: largest dataset ever for document layout analysis. In 2019 International conference on document analysis and recognition (ICDAR). IEEE, 1015–1022. Appendix A Technical Details A.1. Proof for Theorem 5 Proof. (⇐)( ) Let T′T be the true SHT. Any parent-child pair in T′T remains an ancestor-descendant pair in SHT T. Suppose vkv_k and vk′v_k are the next non-descendants of viv_i in T and T′T , respectively. For vk′−1v_k -1, either vk′−1=viv_k -1=v_i, or it is the last descendant of viv_i in T′T . For the former case, k′−1=i<k -1=i<k. For the latter case, since viv_i is an ancestor of vk′−1v_k -1 in T′T , it is also an ancestor of vk′−1v_k -1 in T. Therefore, vk′−1v_k -1 is a descendant of viv_i in T, indicating k′−1<k -1<k. Thus ts′(vi)=[pi,…,pk′−1]⊆[pi,…,pk−1]=ts(vi)ts (v_i)=[p_i,…,p_k -1] [p_i,…,p_k-1]=ts(v_i). T is robust. (⇒)( ) For each parent-child pair (vi,vj)(v_i,v_j) in the true SHT T′T , pj∈ts′(vi)p_j∈ ts (v_i). Since T is robust, we have ts′(vi)⊆ts(vi)ts (v_i) ts(v_i). Therefore, pj∈ts(vi)p_j∈ ts(v_i), indicating that viv_i is an ancestor of vjv_j in T. ∎ A.2. Proof for Theorem 4 Proof. When inserting viv_i, all nodes whose text spans cover the header phrase of viv_i lie on the rightmost path of T (e.g., in 5(c), all nodes highlighted in orange are on the rightmost path at each insertion). viv_i is then inserted as the rightmost child of a node on this rightmost path, and therefore appears last in the pre-order traversal of T. By induction, after every iteration of Algorithm 3, the pre-order traversal of T remains consistent with the increasing order of the node indices. ∎ A.3. Proof for Theorem 1 Proof. (⇒)( ). If T is robust, vjv_j is an ancestor of viv_i in T. Algorithm 3 ensures that for any node, the semantic depth of its cluster is larger than that of the cluster containing its parent. Applying this property along the ancestor chain from viv_i up to vjv_j in T gives sd(vj)<sd(vi).sd(v_j)<sd(v_i). (⇐ ). We prove by induction that each time Algorithm 3 inserts a node viv_i, it places viv_i as a descendant of its true parent vjv_j. Consequently, the tree T remains robust throughout the execution of the algorithm. The key step is to show that, at the moment viv_i is inserted, its true parent vjv_j is a candidate parent of viv_i in Algorithm 3. Since j<ij<i and sd(vj)<sd(vi)sd(v_j)<sd(v_i), it suffices to show that ts(vj)ts(v_j) covers the header phrase of viv_i when viv_i is inserted, which is equivalent to showing that vjv_j lies on the rightmost path of T. Indeed, all nodes inserted into T after vjv_j and before viv_i are placed as descendants of vjv_j in T: they are descendants of vjv_j in the true SHT, and remain descendants of vjv_j in T by our induction hypothesis that T is robust before inserting viv_i. Therefore, when viv_i is inserted, vjv_j remains on the rightmost path of T. ∎ A.4. Depth-Aligned Documents In this class of documents, the indexing node of each cluster must be the leftmost child of its parent in the true SHT (i.e., only case 1 is allowed to occur in 4(a), while case 2 is disallowed). In other words, when a new header formatting is introduced, it must be the first such header in a parent section. Under this condition, the cluster corresponding to the child indexing node is assigned a semantic depth exactly one greater than that of its true parent’s cluster by Algorithm 1. These documents further require clusters to be level-unique, meaning that all nodes within the same cluster are at the same level in the true SHT. As a result, the semantic depth assigned by local-first matches the true depth of every node (i.e., the number of edges from the root to the node) in the true SHT, guaranteeing SD conformance and thus robustness. We refer to such documents as depth-aligned documents (Definition 2). For example, 6(a) is the true SHT of a depth-aligned document. Therefore, the SHT inferred by local-first is robust, as shown in 6(b). We prove Theorem 3 below: Proof. At the moment before inserting node viv_i into T, assume that all nodes currently in T have semantic depths equal to their true depths in T′T . If viv_i is not the indexing node of its cluster, then by condition 2) of depth alignment, sd(vi)sd(v_i) equals the true depth of the indexing node of C(vi)C(v_i), which in turn equals the true depth of viv_i in T′T . If viv_i is the indexing node of its cluster, then by condition 1) of depth alignment, sd(vi)=sd(vj)+1sd(v_i)=sd(v_j)+1, where vjv_j is the true parent of viv_i in T′T . By our assumption that sd(vj)sd(v_j) equals the true depth of vjv_j in T′T , it follows that sd(vi)sd(v_i) also equals its true depth in T′T . ∎ Although depth alignment ensures that local-first produces robust SHTs, global-first may fail on such documents. 6(c) shows a non-robust SHT produced by global-first for a depth-aligned document whose true SHT is shown in 6(a). A.5. Proof for Theorem 5 Proof. If D is well-formatted, then ∀vi,vj∈V∀~v_i,v_j∈ V where viv_i is the parent of vjv_j in T′T , vlv_l’s parent vsv_s in T′T satisfies C(vs)=C(vi)C(v_s)=C(v_i), where l=ind(C(vj))l=ind(C(v_j)). Choosing vk=vsv_k=v_s satisfies all conditions in Definition 4, and thus D is loosely-formatted. The converse does not hold because well-formattedness does not allow parent-child relationships to be inferred from ancestor-descendant occurrences. ∎ A.6. Proof for Theorem 6 Proof. Let the approach from K be Infer-SDK Infer-SD_K with an arbitrary parameter mapping K. Assume D is loosely-formatted. We prove this theorem by contradiction: suppose that the inferred SHT T is not robust. By Theorem 1, there must exist a parent-child pair (vi,vj)(v_i,v_j) in the true SHT T′T that violates SD conformance, i.e., sd(vi)≥sd(vj).sd(v_i)≥ sd(v_j). Among all such violating pairs, choose (vi,vj)(v_i,v_j) with the smallest child index j. vk1,vk2,sd1v_k_1,v_k_2,sd_1 and sd2sd_2 are inferred by Algorithm 4 while scanning the cluster C(vj)C(v_j) of vjv_j. We first establish two inequalities: 1) sd(vi)≤sd1sd(v_i)≤ sd_1. If vk1=viv_k_1=v_i, the claim is immediate. Otherwise, vk1v_k_1 is a true descendant of viv_i in T′T . By the minimality of j, SD conformance holds for (vi,vk1)(v_i,v_k_1), implying sd(vi)<sd(vk1)=sd1sd(v_i)<sd(v_k_1)=sd_1. 2) sd(vi)≤sd2sd(v_i)≤ sd_2. This follows directly from i<ji<j and the definition of sd2sd_2. We now consider vjv_j. Case (a): vjv_j is the indexing node of its cluster. By Algorithm 4, sd(vj)=K(C(vj))⋅sd1+(1−K(C(vj)))⋅sd2+1sd(v_j)=K(C(v_j))· sd_1+ (1-K(C(v_j)) )· sd_2+1 for some K(C(vj))∈[0,1]K(C(v_j))∈[0,1]. Since sd(vi)≤sd1sd(v_i)≤ sd_1 and sd(vi)≤sd2sd(v_i)≤ sd_2, it follows that sd(vi)<sd(vj)sd(v_i)<sd(v_j). Case (b): vjv_j is not the indexing node of its cluster. Let vlv_l be the indexing node of C(vj)C(v_j), with l=ind(C(vj))<jl=ind(C(v_j))<j. Because D is loosely-formatted, there exists a node vkv_k such that vkv_k is an ancestor of vlv_l in T′T and C(vk)=C(vi)C(v_k)=C(v_i). By the minimality of j, SD conformance holds for (vk,vl)(v_k,v_l), implying sd(vk)<sd(vl)sd(v_k)<sd(v_l). Since sd(vk)=sd(vi)sd(v_k)=sd(v_i) and sd(vl)=sd(vj)sd(v_l)=sd(v_j), we again obtain sd(vi)<sd(vj)sd(v_i)<sd(v_j). In both cases, we obtain sd(vi)<sd(vj)sd(v_i)<sd(v_j), a contradiction to our initial assumption that sd(vi)≥sd(vj)sd(v_i)≥ sd(v_j). Therefore, the assumption that T is not robust must be false, and T is robust. ∎ Appendix B SD Inference Family We present the pseudo-code for our infinite family of SHT inference approaches, extending local and global-first, in Algorithm 4. Infer-SDK Infer-SD_K guarantees SHT robustness whenever the input document satisfies SD conformance, i.e., in the true SHT of D, the inferred semantic depth of each parent’s cluster is smaller than that of its child’s cluster (Theorem 1). Algorithm 4 Infer-SDK(V,) Infer-SD_K(V,C) 1: sd(C1)←0sd(C_1)← 0 2: for C∈\C1C \C_1\ in ascending order of ind(C)ind(C) do 3: vk1←argmaxvi∈V,i<ind(C):iv_k_1← _v_i∈ V,i<ind(C):i 4: sd1←sd(C(vk1))sd_1← sd(C(v_k_1)) ⊳ inferred by the local-first approach 5: vk2←argmaxvi∈V,i<ind(C):sd(C(vi))v_k_2← _v_i∈ V,i<ind(C):sd(C(v_i)) 6: sd2←sd(C(vk2))sd_2← sd(C(v_k_2)) ⊳ inferred by the global-first approach 7: sd(C)←K(C)⋅sd1+(1−K(C))⋅sd2+1sd(C)← K(C)· sd_1+(1-K(C))· sd_2+1 8: return sdsd Appendix C Relationship to ZenDB Lin et al. (Lin et al., 2025b) propose an algorithm for SHT construction (Algorithm 1 in (Lin et al., 2025b)). In Section C.1, we prove that this algorithm is equivalent to our two-stage workflow with global-first SD inference: for each node viv_i, both approaches select as viv_i’s parent the node vjv_j with the largest index j<ij<i such that ind(C(vj))<ind(C(vi))ind(C(v_j))<ind(C(v_i)). Moreover, in Section 4.4, we state one requirement of well-formattedness as consistency between each parent-child pair and the first occurrences of their corresponding visual patterns. We show in Section C.2 that this requirement is equivalent to Lin et al.’s original well-formattedness definition (Definition 1 in (Lin et al., 2025b)), which requires consistency among the ancestor visual-pattern lists of all nodes within the same cluster. Lin et al. (Lin et al., 2025b) do not go beyond well-formattedness and do not consider properties such as robustness or compactness. C.1. SHT Construction ZenDB proposes Algorithm 1 in (Lin et al., 2025b) to construct SHTs. We show that this algorithm is equivalent to our two-stage workflow, with global-first SD inference (Algorithm 2) followed by SHT assembly (Algorithm 3). Theorem 1. Our two-stage workflow with global-first SD inference is equivalent to Algorithm 1 of ZenDB. Proof. For simplicity, we use ind(vi)ind(v_i) to denote ind(C(vi))ind(C(v_i)). 1) Removing the constraint on text span in Line 8 of Algorithm 1 of ZenDB. In Algorithm 1 of ZenDB, when inserting a node viv_i (Line 6), the algorithm chooses the node vjv_j with the largest index j<ij<i such that ind(vj)<ind(vi)ind(v_j)<ind(v_i) as the parent of viv_i, where ind(vj)<ind(vi)ind(v_j)<ind(v_i) is implied by Line 7, and the maximality of j is implied by Line 8. At this point in Algorithm 1, ts(vj)=[pj,…,ps−1]ts(v_j)=[p_j,…,p_s-1], where psp_s corresponds to the next non-descendant vsv_s of vjv_j in T. vsv_s is thus inserted before viv_i, implying ind(vs)<ind(vi)ind(v_s)<ind(v_i). The maximality of j further implies s>is>i. Therefore, pi∈ts(vj)p_i∈ ts(v_j) holds automatically, and the constraint ind(vi)∈ts(vj)ind(v_i)∈ ts(v_j) in Line 8 of Algorithm 1 can be removed without changing the algorithm’s behavior. After removing this constraint on text span, the nested loops (Line 4-10) in Algorithm 1 of ZenDB can be reduced to the following single loop, where we additionally replace the constraint vj∈V−VCv_j∈ V-V_C (Line 7) with vj∈Tv_j∈ T: 1: for vi∈Vv_i∈ V in ascending order of i do 2: vk←argmaxvj∈T,ind(vj)<ind(vi):jv_k← _v_j∈ T,ind(v_j)<ind(v_i):j 3: Add node viv_i to T as the rightmost child of vkv_k. 2) Equivalence to our two-stage workflow with global-first SD inference. Algorithm 3 (Line 3) selects vkv_k as the parent of viv_i, where k is the largest index j such that vj∈Vv_j∈ V, pi∈ts(vj)p_i∈ ts(v_j), and sd(C(vj))<sd(C(vi))sd(C(v_j))<sd(C(v_i)). Under global-first SD inference, the ordering of semantic depths is consistent with the ordering of cluster indices. Therefore, sd(C(vj))<sd(C(vi))sd(C(v_j))<sd(C(v_i)) is equivalent to ind(vj)<ind(vi)ind(v_j)<ind(v_i). As argued in 1), the condition pi∈ts(vj)p_i∈ ts(v_j) is also redundant for Algorithm 3 under global-first. Line 3 of Algorithm 3 under global-first can thus be reduced to the following line: 1: vk←argmaxvj∈T,ind(vj)<ind(vi):jv_k← _v_j∈ T,ind(v_j)<ind(v_i):j This line is identical to Line 2 of the single loop in 1). Therefore, our two-stage workflow under global-first is equivalent to Algorithm 1 of ZenDB. ∎ C.2. Well-Formattedness ZenDB defines a document D, given its true SHT T′T and clusters C, to be well-formatted via Definition 1 in (Lin et al., 2025b) if it satisfies the following two conditions: 1) Any two nodes that are siblings (i.e., have the same parent) in T′T must belong to the same cluster. 2) Any two nodes belonging to the same cluster must share identical visual prefixes, denoted visprevispre, defined as the sequences of clusters along the paths from the root to the nodes in T′T . In Section 4.4, we rephrase the second condition as a consistency requirement between any parent-child pair and the first occurrences of their corresponding visual patterns. We now show that this rephrasing (i.e., condition (2) in Theorem 2) does not change ZenDB’s original definition (i.e., condition (1) in Theorem 2): Theorem 2. Consider a document D with nodes V, clusters C, and true SHT T′T . The following two conditions are equivalent: (1) ∀vi,vj∈V∀~v_i,v_j∈ V, if C(vi)=C(vj)C(v_i)=C(v_j), then vispre(vi)=vispre(vj)vispre(v_i)=vispre(v_j), where vispre(v)=[C(v1),…,C(v)]vispre(v)=[C(v_1),…,C(v)] is the sequence of clusters along the path from the root v1v_1 to v in T′T . (2) ∀vi,vj∈V∀~v_i,v_j∈ V, if viv_i is the parent of vjv_j in T′T , then there exists a parent-child pair (vk,vl)(v_k,v_l) in T′T such that l=ind(C(vj))l=ind(C(v_j)) and C(vk)=C(vi)C(v_k)=C(v_i). (1)⇒(2)(1) (2). If (1) holds for D, vispre(vj)=vispre(vl)vispre(v_j)=vispre(v_l) implies that the parents of vjv_j and vlv_l in T′T belong to the same cluster, establishing (2). (2)⇒(1)(2) (1). If (2) holds for D, then for viv_i and vjv_j in the same cluster C, the true parent of viv_i belongs to the same cluster as the true parent of vind(C)v_ind(C), and the same holds for vjv_j. Thus, viv_i, vjv_j, and vind(C)v_ind(C) all have parents in the same cluster. Applying the same argument recursively to their parents, we conclude that viv_i and vjv_j share identical clusters at every level along their paths to the root. Hence, vispre(vi)=vispre(vj)vispre(v_i)=vispre(v_j). ∎ Appendix D Datasets Table 7. Datasets are collected from existing sources and cited accordingly. Src. #Docs: number of documents in the source. Src. #Qs: number of questions in the source. For Civic, metadata are provided, allowing flexible question curation; we therefore report –. #Const. Docs (k): number of source documents constituting each composite document (i.e., k+1k+1) used in our evaluation (Section 5.1). Src. Query Example: an example question on the original source (single document). Modified Query Example: its modified version for our agentic document QA evaluation. Red: modified text. Datasets Src. #Docs Src. #Qs #Const. Docs Src. Query Example Modified Query Example Civic (Lin et al., 2025b; Center, 2024) 19 – 4 (k=3k=3) Return a list of project names for all projects whose status matches the status of project ‘Westward Beach Road Shoulder Repairs (CalOES Project)’ According to the report for the meeting on January 26, 2022: Return a list of project names for all projects whose status matches the status of project ‘Westward Beach Road Shoulder Repairs (CalOES Project)’ Contracts (Koreeda and Manning, 2021b) 73 1241 5 (k=4k=4) Determine the relationship between contract ‘064-19 Non Disclosure Agreement 2019’ and a hypothesis ℋH (one of ‘Entailment’, ‘Contradiction’, or ‘NotMentioned’) Return a list of contract names whose relationship to ℋH is the same as that of the contract ‘064-19 Non Disclosure Agreement 2019’. Finance (Islam et al., 2023) 84 150 2 (k=1k=1) What is the FY2018 capital expenditure amount (in USD millions) for 3M? Same as the source query. Papers (Dasigi et al., 2021) 416 1451 3 (k=2k=2) How big is the ANTISCAM dataset? According to the paper ‘End-to-End Trainable Non-Collaborative Dialog System’: How big is the ANTISCAM dataset? We compose real-world documents and sample questions from existing datasets spanning diverse lengths, domains, and templates into our evaluation datasets (Section 5.1). We describe each dataset in detail (Table 7). Civic. The source contains Malibu City Council agenda reports (Center, 2024), each using a complex, nested hierarchy to describe civic projects and their attributes (e.g., status, updates, start and completion times). We use each report’s meeting date as its name, placed on its prepended title page. Contracts. The source contains non-disclosure agreements (NDAs) with hierarchical structures indicated by list items. We use the raw PDF file names as contract names, placed on title pages. Finance. The source contains financial filings (10-Ks, 10-Qs, 8-Ks, and earnings reports) from U.S. publicly traded companies between 2015 and 2023. We use a hash string as each document’s name and place it on the corresponding title page; thus, to answer a (source) question (which specifies the company) over a composite document, one must first identify the correct constituent document (with hashed name) by inspecting partial content before retrieving relevant text. Moreover, since some (source) questions rely on tables, we mitigate LLMs’ difficulty in processing serialized tables by reformatting them into Markdown (Sui et al., 2024; Agents, 2025). Specifically, each table row is represented as a Markdown section marked with ##, and each cell value v, together with its corresponding column header C, is represented as a list item “- C:vC:v” under this section. Papers. The source contains 416 natural language processing (NLP) research papers in its test split. We extract paper titles from metadata and place them on title pages. Appendix E Additional Evaluations and Results In this section, we provide detailed results and analysis of evaluations mentioned in the main paper. E.1. True Header Ablation In Section 6.2, we summarized the results of SHT inference with SHED using extracted headers V versus true headers V′V . Here, we provide detailed results and analysis. Results in Table 8 show that with true headers V′V , SHED’s SHTs reach nearly perfect robustness (e.g., 96%–99% M↓M_ recall across all datasets), with the remaining 1%–4% arising from documents that violate SD conformance (Section 4.1). V′V improves almost all metrics across all datasets over extracted headers V, most notably on Contracts (2%–12%) and Finance (0%–20%), whose header identification accuracy is relatively low (Table 2). However, on average, the gap between V′V and V is moderate (3%–6% across all metrics), so SHED with V still works well (because the text span of a missing true header v∈V′ ∈ V V is usually contained in that of the preceding header, typically a sibling or parent). Therefore, we use V for SHED throughout our evaluation, which performs comparably to V′V and reflects the realistic setting where V′V is unavailable. Table 8. Robustness (Recall), compactness (Precision), and their F-1 of SHTs inferred by SHED from true headers. Parentheses indicate the percentage difference from SHED with extracted headers. Dataset Top-down: M↓M_ Bottom-up: M↑M_ Recall Precision F-1 Recall Precision F-1 Civic 0.96 (+6) 0.96 (+5) 0.95 (+6) 0.94 (+2) 0.93 (+0) 0.93 (+0) Contracts 0.99 (+2) 0.99 (+11) 0.98 (+11) 0.94 (+12) 0.97 (+5) 0.94 (+11) Finance 0.96 (+2) 0.95 (+0) 0.92 (+2) 0.71 (+2) 0.91 (+20) 0.76 (+11) Papers 0.96 (+0) 0.96 (+1) 0.95 (+1) 0.86 (+4) 0.94 (+1) 0.88 (+4) Avg. 0.97 (+3) 0.96 (+4) 0.95 (+5) 0.86 (+5) 0.94 (+6) 0.88 (+6) E.2. Compactness-Depth Correlation To show that depth is a reasonable proxy for compactness, we evaluate the correlation between the two over all 955 documents (Table 1 in Section 5.1), using SHTs inferred by SHED from both extracted and true headers (Table 3 in Section 6.2). As shown in Figure 8, we group SHTs by their inferred depth relative to the true depth into three bins, balancing the number of instances and depth ratio range. The average bottom-up compactness with extracted (true) headers is 0.92 (0.95), 0.91 (0.94), and 0.83 (0.91) for bins (0.5,1](0.5,1], (1,1.2](1,1.2], and (1.2,2.2](1.2,2.2], respectively, indicating that deeper SHTs tend to be less compact. Figure 8. Compactness vs. depth relative to true SHT. A point shows average compactness of SHTs in a depth ratio bin, from extracted (blue) or true (green) headers. E.3. Scalability Analysis: Document Composition In Section 8.3, we described results of SHED and baselines on composite documents of varying sizes, from 1 to k to 2(k+1)2(k+1). Here, we provide detailed results and analysis. For single originals (size 1), we use the source queries rather than those adapted for composites (see Table 7). Robustness and Compactness. We report the results (M↓M_ / M↑M_ recall, precision, and F-1) of composition sizes 1 and 2(k+1)2(k+1) in Table 9 and Table 10 (the k+1k+1 results are in Table 3 in Section 6). The SHTs inferred by SHED stay robust and compact as composition size grows: recall, precision and F-1 change by at most 2%. They also beat baselines by a widening margin: their M↓M_ (M↑M_ ) F-1 are 7%–56% (9%–39%), 9%–68% (10%–49%), and 13%–71% (15%–55%) higher than baselines at sizes 1, k+1k+1, and 2(k+1)2(k+1). QA accuracy & cost. We show the QA accuracy and total cost across composition sizes in Figure 9. Across all composition sizes, SHT-based agent with SHED is accurate (0.71—0.73 on average) at low cost ($12–$28 total, up to 28×28× cheaper than baselines), on par with true SHTs (0.71—0.74, $11–$25). Its gains widen with size: it is up to 7% to 19% to 27% more accurate than the baselines at sizes 1, k+1k+1, and 2(k+1)2(k+1); its cost rises only 1.4×1.4× as size doubles. Specifically, at size 1 the vanilla-grep agent is 2% below vanilla-in-context but nearly 4× cheaper. With the SHT-based agent, Deep drops fastest (6%, 19%, 27% lower than SHED) because its upper-level text spans grow with size, giving poor compactness and overly context. LLM-text and LLM-vision match SHED at size 1 (within 1%) but cost 6.5×6.5× and 14×14× more; their accuracy drops 7% and 6% at k+1k+1 and another 5% and 6% at 2(k+1)2(k+1), as inferring an SHT from the full concatenated document gets harder with longer contexts. GROBID improves on larger compositions due to artificial merging: it infers an SHT per document and merges them under a virtual root (Section 6.1); it stays uniformly low, yielding barely usable structure at any size. SHED’s gain over Wide does not widen much (4%, 8%, 6%), likely because Wide’s per-node text spans stay small and its flat SHT (only ~0.5% of GPT-5.4’s 1M window even at 2(k+1)2(k+1)) still lets the agent infer a partial hierarchy. Table 9. M↓M_ and M↑M_ results at composition size 11 (a single original document), in the same format as Table 3. Approach Recall (Robustness) Precision (Compactness) F-1 (Trade-off) Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Top-down: M↓(T)=avgv∈T′f(v)M_ (T)=avg_v∈ T f(v), where f(v)f(v) calculates recall, precision, and F-1 score of ts(v)ts(v) relative to ts′(v)ts (v). Deep 0.93 0.99 0.99 0.97 0.97 0.28 0.29 0.15 0.35 0.27 0.37 0.37 0.19 0.44 0.34 Wide 0.67 0.81 0.80 0.78 0.76 0.92 0.94 0.95 0.97 0.95 0.69 0.79 0.79 0.79 0.76 GROBID 0.35 0.79 0.71 0.78 0.66 0.17 0.34 0.71 0.83 0.51 0.18 0.38 0.62 0.77 0.49 LLM-text 0.96 0.75 0.92 0.97 0.90 0.97 0.60 0.89 0.97 0.86 0.96 0.58 0.86 0.96 0.84 LLM-vision 0.93 0.77 0.95 0.94 0.90 0.93 0.61 0.72 0.96 0.80 0.93 0.61 0.68 0.95 0.79 SHED 0.89 0.97 0.93 0.97 0.94 0.89 0.92 0.93 0.95 0.93 0.88 0.92 0.88 0.94 0.91 Bottom-up: M↑(T)=avgv∈T′f(v)M_ (T)=avg_v∈ T f(v), where f(v)f(v) calculates recall, precision, and F-1 score of H(v)H(v) relative to H′(v)H (v). Deep 0.94 0.89 0.96 0.87 0.91 0.36 0.56 0.24 0.64 0.45 0.48 0.56 0.31 0.68 0.51 Wide 0.31 0.43 0.26 0.26 0.31 0.94 0.95 0.97 0.96 0.96 0.46 0.54 0.38 0.34 0.43 GROBID 0.16 0.46 0.35 0.76 0.43 0.30 0.71 0.55 0.92 0.62 0.20 0.52 0.38 0.81 0.48 LLM-text 0.90 0.58 0.72 0.82 0.76 0.73 0.62 0.79 0.88 0.76 0.80 0.57 0.73 0.82 0.73 LLM-vision 0.91 0.34 0.47 0.81 0.63 0.76 0.73 0.77 0.96 0.81 0.82 0.43 0.55 0.85 0.66 SHED 0.92 0.84 0.69 0.84 0.83 0.93 0.92 0.69 0.93 0.87 0.93 0.85 0.65 0.86 0.82 Table 10. M↓M_ and M↑M_ results at composition size 2(k+1)2(k+1), in the same format as Table 3. Approach Recall (Robustness) Precision (Compactness) F-1 (Trade-off) Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Civic Contracts Finance Papers Avg. Top-down: M↓(T)=avgv∈T′f(v)M_ (T)=avg_v∈ T f(v), where f(v)f(v) calculates recall, precision, and F-1 score of ts(v)ts(v) relative to ts′(v)ts (v). Deep 0.94 0.99 1.00 0.97 0.97 0.20 0.12 0.08 0.14 0.13 0.28 0.16 0.10 0.20 0.19 Wide 0.72 0.82 0.82 0.78 0.78 0.93 0.90 0.97 0.97 0.94 0.74 0.73 0.82 0.79 0.77 GROBID 0.55 0.84 0.76 0.76 0.73 0.30 0.48 0.76 0.82 0.59 0.30 0.48 0.67 0.75 0.55 LLM-text 0.97 0.94 0.79 0.96 0.91 0.97 0.66 0.55 0.95 0.79 0.96 0.67 0.51 0.95 0.77 LLM-vision 0.98 0.87 0.95 0.91 0.93 0.94 0.55 0.76 0.84 0.77 0.94 0.53 0.72 0.83 0.76 SHED 0.90 0.97 0.94 0.95 0.94 0.91 0.88 0.96 0.95 0.92 0.90 0.86 0.91 0.93 0.90 Bottom-up: M↑(T)=avgv∈T′f(v)M_ (T)=avg_v∈ T f(v), where f(v)f(v) calculates recall, precision, and F-1 score of H(v)H(v) relative to H′(v)H (v). Deep 0.94 0.91 0.99 0.85 0.92 0.27 0.20 0.11 0.22 0.20 0.37 0.22 0.15 0.29 0.26 Wide 0.32 0.41 0.27 0.25 0.31 0.94 0.94 0.98 0.94 0.95 0.46 0.53 0.39 0.34 0.43 GROBID 0.22 0.48 0.39 0.73 0.45 0.42 0.73 0.59 0.91 0.66 0.28 0.52 0.41 0.78 0.50 LLM-text 0.76 0.61 0.38 0.78 0.63 0.72 0.76 0.57 0.93 0.74 0.72 0.64 0.42 0.81 0.65 LLM-vision 0.86 0.41 0.47 0.68 0.60 0.94 0.73 0.77 0.85 0.82 0.88 0.48 0.54 0.72 0.66 SHED 0.93 0.81 0.70 0.81 0.81 0.93 0.92 0.68 0.92 0.87 0.93 0.83 0.64 0.84 0.81 (a) Accuracy: usefulness of SHTs. (b) Accuracy: SHT ablation. (c) Cost: usefulness of SHTs. (d) Cost: SHT ablation. Figure 9. Average accuracy and total cost (USD) as the composition size (i.e., the number of concatenated documents) grows from the original (1) to twice the size used in Section 7 (2(k+1)2(k+1)), where k varies by dataset (Table 7 in Appendix D). The panels replicate the experiments in Sections 7.2 (Figures 9(a), 9(c)) and 7.4 (Figures 9(b), 9(d)). E.4. Scalability Analysis: Complex Documents with Synthetic Q&A In Section 8.3, we briefly described the evaluation results of SHED and baselines on three new datasets (CFR, ETSI, and FERC) that contain individually complex documents without concatentation. Here, we describe the details of the three new datasets, including their document collection, their Q&A synthesis (summarized in Table 11), as well as the QA evaluation metric and detailed results and analysis, as summarized in Table 11. Document collection. We use dataset-specific criteria to select documents with complex structures: for CFR, we select volumes with at least 6 agency sections each; for ETSI, we select documents with at least 40 pages. Documents in FERC are from 2020–2025. Each document has a table of contents embedded in its PDF, which we extract via PyMuPDF’s get_toc as the true SHT. Q&A synthesis. For each document, we design query templates that require document’s structure, and then instantiate each template with entities in the document to generate queries. For example, documents in CFR have a three-level structure: each document contains multiple agencies as sections, each agency contains multiple regimes as subsections, and each regime contains multiple regulations as subsubsections (agency → regime → regulation). Therefore, we design a query template that asks for all agencies whose regulations in a given regime R relate to a given hypothesis H the same way as a given agency X. For each document, we select a regime R, a regulation H as the hypothesis, and an agency X, to generate a query for that document. Queries for ETSI and FERC are generated similarly, as shown in Table 11. Evaluation metric. Each query requests a set of entities (e.g., agency names, as shown in Table 11). To evaluate answer accuracy, we split the generated answer on line breaks to extract entities, normalize them (canonicalizing characters, lowercasing, and removing punctuation and whitespace), and compute the F-1 score against the ground-truth entity set. Results. Table 12 shows that SHED outperforms Wide by 8%–15% (16%–26%) in recall and 1%–13% (12%–20%) in F-1 across datasets under M↓M_ (M↑M_ ). Table 13 shows that SHED’s QA accuracy is 7%–18% higher on average than the 3 baselines, at nearly the cheapest cost (Wide’s) and 15×15× below the costliest (vanilla-in-context). On CFR, SHED still achieves good QA accuracy despite low header-identification recall: the missed headers are mostly regulations (the lowest level, ~1.6K per document), whose content the agent recovers from the parent section’s (regime’s) text span. FERC shows low accuracy across strategies due to query complexity: queries require finding all environmental-effect sections and classifying experts’ sentiments from all corresponding analyses (subsections). Table 11. Three new datasets, collected from inherently complex real-world documents. Avg. Doc Size: average word count per document in each dataset. #Docs (#Qs): number of documents (questions) in each dataset. Structure: document’s hierarchical structure, represented as section → subsection → subsubsection. Query template: natural-language template instantiated with entities in documents. Datasets #Docs Avg. Doc Size #Qs Structure Query Template CFR (Office of the Federal Register, National Archives and Records Administration, 2025) 30 415,115 40 agency → regime → regulation List all agencies whose regulations in regime R (e.g., FOIA, Privacy) relate to hypothesis H the same way (Entailment / Contradiction / NotMentioned) as agency X. ETSI (European Telecommunications Standards Institute, 2026) 49 30,485 49 equipment category → characteristic → attribute List all characteristics, spanning ≥2≥\!2 equipment categories (transmitter / receiver / duplex), whose attribute A (Definition / Method-of-measurement / Limits) satisfies predicate P. FERC (Federal Energy Regulatory Commission, 2026) 40 49,126 53 resource type → environmental effect → staff analysis List all environmental effects whose resource type (e.g., aquatic, terrestrial, T&E species, recreation, cultural) differs from that of effect X but whose staff-analysis sentiment (positive / negative / neutral) is the same as X. Table 12. Robustness (Recall), compactness (Precision), and their F-1 of SHTs inferred by Wide and SHED on the three new datasets in Section 8.3. Green: better of the two approaches per dataset per metric. Approach Recall Precision F-1 CFR ETSI FERC Avg. CFR ETSI FERC Avg. CFR ETSI FERC Avg. Top-down: M↓(T)M_ (T) Wide 0.71 0.77 0.68 0.72 0.47 0.96 0.93 0.78 0.42 0.76 0.69 0.62 SHED 0.79 0.89 0.83 0.84 0.43 0.95 0.91 0.76 0.43 0.89 0.79 0.70 Bottom-up: M↑(T)M_ (T) Wide 0.19 0.19 0.43 0.27 0.75 0.98 0.91 0.88 0.28 0.29 0.54 0.37 SHED 0.35 0.45 0.63 0.48 0.58 0.63 0.90 0.70 0.40 0.49 0.71 0.54 Table 13. Average QA accuracy and total cost (USD, inside parenthesis) on the three new datasets in Section 8.3. Green: highest accuracy (lowest cost) per dataset. Strategy CFR ETSI FERC Avg. (Tot.) Vanilla-in-context 0.65 (111.1) 0.87 (4.8) 0.21 (12.3) 0.58 (128.3) Vanilla-grep agent 0.67 (4.8) 0.66 (6.5) 0.23 (18.0) 0.52 (29.2) SHT-based agent (Wide) 0.71 (3.6) 0.83 (1.1) 0.34 (3.0) 0.63 (7.7) SHT-based agent (SHED) 0.78 (4.3) 0.90 (1.7) 0.42 (2.4) 0.70 (8.5) E.5. Scalability Analysis: SHT Inference Latency We test SHT inference latency for the approaches in Section 6, plus SmolDocling-256M-preview (Appendix E.6, a new learning-based baseline that jointly models the layout and semantics of a PDF), since running the costlier methods (e.g., LLM-vision) on large corpora exceeds our budget—scaling to 1M documents like those we evaluate would cost >>250K USD—we instead evaluate on 80 composite documents (20 sampled from each of the four datasets in Table 1) and report the estimated latency over all 955 documents in Table 14. Overall, SHED needs 5 hours to process millions of tokens, showing good scalability; employing parallelism would further improve scalability. Testbed. We run the large model (HURIDOCS, 2025) used by SHED (for header identification on Civic and Contracts; Sec. 5.2) and SmolDocling-256M-preview (Appendix E.6) on a GPU machine with one NVIDIA L4 GPU with 24 GiB, 4 vCPUs, and 16 GiB RAM. We run all other experiments that do not involve local neural-network inference on a CPU machine with one 2.20 GHz Intel Xeon (8 cores, 16 threads) and 15 GiB RAM, including SHED’s smaller model (Ke et al., 2017) for header identification on Finance and Papers, visual pattern extraction and SHT assembly, and GROBID, LLM-text, LLM-vision. Results. Each approach processes documents sequentially. Table 14 shows that GROBID, LLM-text, and LLM-vision infer SHTs for all 955 documents in 4, 2, and 5 hours. However, GROBID produces low-quality SHTs (poor robustness and compactness; Table 3); LLM-text and LLM-vision do not scale in cost (the LLM-based ones would run ~$0.2M per 1M documents). SHED takes about 5 hours to infer SHTs for all 955 documents (in total nearly 54K pages and 30M tokens) sequentially, showing good scalability. Specifically, 90%–94% of time is spent on header identification by Huridocs (HURIDOCS, 2025; Ke et al., 2017), the rest visual-pattern extraction and SHT construction. Deep and Wide should be similar to SHED in latency, since they only skip visual-pattern extraction (which accounts for up to 10% of SHED’s latency), but their SHTs are far less robust or compact. SmolDocling-256M-preview would take ~11.4 days, far slower than SHED, since it runs more complex models to build SHTs end-to-end rather than just for header identification. Table 14. SHT inference latency (average seconds per document), measured on 20 sampled composite documents per dataset. Est. Tot.: total latency (hours) for all 955 documents in Table 1, as extrapolated estimates via the samples. Approach Civic Contracts Finance Papers Est. Tot. (h) GROBID 14 15 52 8 4 LLM-text 8 5 33 3 2 LLM-vision 13 9 93 11 5 SHED 22 18 48 13 5 SmolDocling-256M-preview 229 308 5,074 747 273 E.6. An Advanced SHT Inference Baseline For approaches that jointly model PDF layout and semantics to infer structure, we’ve already evaluated LLM-vision (GPT-5.4) in Sections 6 and 7, which is state-of-the-art—e.g., on DocVQA, GPT-4o scores 92.8% (LLM-Stats, 2026), beating fine-tuned LayoutLMv3 (83.4%) (Huang et al., 2022) by over 9%; our baseline uses the stronger GPT-5.4. To broaden our baselines with this line of approaches, we further evaluate SmolDocling-256M-preview (Nassar et al., 2025), which is a learning-based approach that generates a Markdown to encode hierarchical structure. Due to resource constraints, we evaluate only the 80 documents from Appendix E.5. Table 15reports the top-down and bottom-up recall, precision, and F-1 of its SHTs, which average up to 56% below SHED. Possible causes are: (1) its inferred SHTs are mostly flat (78 of the 80 have only 1-level non-root nodes), and (2) its header identification is less accurate than SHED’s (recall/precision/F-1 is 0.82/0.84/0.83 on Civic, 0.20/0.74/0.31 on Contracts, 0.85/0.46/0.58 on Finance, and 0.82/0.82/0.82 on Papers). Table 15. Robustness (Recall), compactness (Precision), and their F-1 of SHTs inferred by SmolDocling-256M-preview, on 80 sampled documents (20 per dataset). Parentheses indicate the percentage difference from SHED (Table 3). Dataset Top-down: M↓M_ Bottom-up: M↑M_ Recall Precision F-1 Recall Precision F-1 Civic 0.66 (−-24) 0.88 (−-3) 0.69 (−-20) 0.26 (−-66) 0.86 (−-7) 0.40 (−-53) Contracts 0.76 (−-21) 0.43 (−-45) 0.40 (−-47) 0.24 (−-58) 0.74 (−-18) 0.33 (−-50) Finance 0.70 (−-24) 0.89 (−-6) 0.70 (−-20) 0.22 (−-47) 0.88 (+17) 0.33 (−-32) Papers 0.63 (−-33) 0.83 (−-12) 0.66 (−-28) 0.26 (−-56) 0.87 (−-6) 0.35 (−-49) Avg. 0.69 (−-25) 0.76 (−-16) 0.61 (−-29) 0.25 (−-56) 0.84 (−-3) 0.35 (−-46) E.7. Sensitivity of SHED To assess SHED’s sensitivity to the SD inference approach (Section 3), we compare the robustness and compactness of SHTs inferred by global-first and local-first (our previous implementation; Section 5.2) on the four datasets in Table 1 (Table 16). To further justify our choice of local-first, we evaluated both approaches on 40 real-world documents from SAFEDOCS (et al.(2021), PI) in Section 4.4 where local-first guarantees robustness while global-first does not (Table 17). Results. Table 16 shows that global- and local-first achieve nearly identical robustness and compactness across datasets on M↑M_ and M↓M_ (within 1% difference in average recall, precision, and F-1), indicating SHED’s stability across the two approaches over the four datasets. This is partly because over 60% of documents are loosely-formatted, for which SHED guarantees robustness under any SD inference approach in Section 4.3 (Theorem 6). Table 17 shows that, over 40 real-world documents other than the ones in the four datasets, local-first guarantees robustness (recall=1) while global-first does not, and local-first achieves 4% (5%) higher average F-1 than global-first on M↓M_ (M↑M_ ). This further justifies our choice of local-first for SHED in Section 5.2. Table 16. Robustness (Recall), compactness (Precision), and their trade-off (F-1) of SHTs inferred by SHED with the global-first SD inference. Parentheses: difference from local-first (Table 3), in percentage points. Avg.: stratified averages across datasets. Dataset Top-down: M↓M_ Bottom-up: M↑M_ Recall Precision F-1 Recall Precision F-1 Civic 0.90 (+0) 0.91 (+0) 0.89 (+0) 0.92 (+0) 0.93 (+0) 0.93 (+0) Contracts 0.97 (+0) 0.88 (+0) 0.87 (+0) 0.82 (+0) 0.92 (+0) 0.84 (+1) Finance 0.94 (+0) 0.95 (+0) 0.90 (+0) 0.69 (+0) 0.70 (−-1) 0.65 (+0) Papers 0.96 (+0) 0.95 (+0) 0.94 (+0) 0.82 (+0) 0.93 (+0) 0.84 (+0) Avg. 0.94 (+0) 0.92 (+0) 0.90 (+0) 0.81 (+0) 0.87 (+0) 0.82 (+1) Table 17. Robustness (Recall), compactness (Precision), and their F-1 of SHTs inferred by SHED with local- and global-first SD inference over 40 real-world documents (et al.(2021), PI). Approach Top-down: M↓M_ Bottom-up: M↑M_ Recall Precision F-1 Recall Precision F-1 global-first 0.97 0.94 0.92 0.94 0.81 0.84 local-first 1.00 0.96 0.96 1.00 0.84 0.89 Appendix F Prompts F.1. LLM-based SHT Inference LLM-text use the following prompt to infer SHT given serialized document text: ⬇ 1 ======================== System Prompt ======================== 2 You are given a document. Your task is to extract and organize its Table of Contents (ToC). 3 4 Instructions: 5 6 1. Identify **all headings at every level** in the document (e.g., title, sections, subsections, sub-subsections, and any deeper levels). 7 2. **Use the exact wording of each heading as it appears** - do NOT paraphrase, shorten, or modify. 8 3. Preserve the original capitalization, punctuation, and numbering. 9 4. Infer the hierarchy levels based on formatting, numbering, or context. 10 5. Maintain the original order of appearance. 11 6. Do NOT invent, merge, or omit any headings. 12 7. Exclude any text that is not a heading. 13 14 Formatting requirements: 15 16 * Use the following Markdown format to represent hierarchy: 17 18 ‘markdown 19 # Title 20 ## Section Header 21 ### Subsection Header 22 #### Sub-subsection Header 23 ‘ 24 25 * The number of ‘#‘ symbols indicates the hierarchy level. 26 27 * Include exactly one space between the ‘#‘ symbols and the header text. 28 29 * Extend to deeper levels as needed (e.g., ‘#####‘, ‘######‘, etc.). 30 31 * Do NOT skip levels (e.g., do not jump from ‘#‘ to ‘###‘). 32 33 * Output only the Table of Contents in Markdown format. 34 35 * Do NOT include any explanations or extra text. 36 37 ========================= User Prompt ========================= 38 DOCUMENT: 39 doc_txt 40 41 TOC IN MARKDOWN: The prompt for LLM-vision is largely the same, with two modifications: (1) the first sentence of the system prompt is changed to: “You are given images of a document’s pages. Your task is to extract and organize a Table of Contents (ToC) of the document from the images”; (2) the placeholder doc_txt is replaced with a batch of page images in reading order. F.2. LLM-as-judge Below is the prompt for LLM-as-judge on Finance: ⬇ 1 ======================== System Prompt ======================== 2 You are an LLM-as-judge. Grade a candidate answer against a ground-truth reference answer for a finance question. 3 4 INPUTS (verbatim): 5 - QUESTION 6 - REFERENCE_ANSWER 7 - CANDIDATE_ANSWER 8 9 HARD RULES 10 - Use ONLY QUESTION, REFERENCE_ANSWER, CANDIDATE_ANSWER. No outside knowledge. 11 - Output ONE JSON object only (no extra text). 12 - Scoring must follow the rubric below exactly. 13 14 OUTPUT JSON SCHEMA (strict) 15 16 "score": number, // final in [0, 1] 17 "question_type": "numeric" | "boolean" | "list" | "explanatory" | "mixed", 18 "extracted_candidate_answer": 19 "text_span": string, 20 "normalized_value": number | null, 21 "normalized_units": "usd_millions" | "usd_billions" | "percent" | "ratio" | "days" | "text" | "none" | null 22 , 23 "reference_answer": 24 "text": string, 25 "normalized_value": number | null, 26 "normalized_units": "usd_millions" | "usd_billions" | "percent" | "ratio" | "days" | "text" | "none" | null 27 , 28 "subscores": 29 "polarity_or_core": number, // [0,1] 30 "numeric_accuracy": number, // [0,1] 31 "units_and_scale": number, // [0,1] 32 "completeness": number, // [0,1] 33 "no_contradictions": number // [0,1] 34 , 35 "reasons": [string], 36 "confidence": number // in [0,1] 37 38 39 QUESTION TYPE CLASSIFICATION 40 - "numeric": asks for a single numeric value/ratio/percent/days/currency amount. 41 - "boolean": asks Yes/No (or equivalent) with or without brief justification. 42 - "list": asks to list items (e.g., securities, acquisitions, geographies). 43 - "explanatory": asks for drivers/why/what caused, narrative required. 44 - "mixed": combines boolean + explanation or numeric + explanation. 45 46 NUMERIC NORMALIZATION (use for numeric parts) 47 - Extract the first unambiguous numeric target in CANDIDATE_ANSWER that appears to answer the question. 48 - Accept: "$1577.00", "1,577", "0.66", "65.4%", "1.9 %". 49 - Remove commas. 50 - Percent handling: 51 - If percent sign present => units "percent", numeric is the percent number (e.g., "1.9%" -> 1.9). 52 - If QUESTION requests percent but candidate omits "%" and also omits the word "percent", treat unit as ambiguous and score units accordingly (do NOT assume percent). 53 - Scale words MUST be honored: 54 - million/mn/m => scale of millions; billion/bn/b => scale of billions. 55 - If QUESTION requests USD millions (or billions), candidate must present the answer in that unit; merely giving an equivalent in another unit is NOT acceptable unless candidate explicitly converts AND presents the requested unit as the final answer. 56 - Rounding: 57 - If QUESTION says "Round to two decimal places": candidate must match within +-0.005. 58 - If QUESTION says "Round to one decimal place": match within +-0.05. 59 - If QUESTION not specify rounding: require exact match to reference after normalization; if reference shows 1 decimal allow +-0.05, if 2 decimals allow +-0.01. 60 61 CONTRADICTIONS (global) 62 - If candidate contains internal contradictions (multiple conflicting finals, "Yes" then "No", different numbers) then set "no_contradictions"=0; otherwise 1. 63 64 SCORING RUBRIC (deterministic) 65 Compute subscores, then weighted sum. Clamp final to [0,1]. 66 67 A) For question_type="numeric" 68 - polarity_or_core = 1 (not applicable) 69 - units_and_scale: 70 - 1 if units/scale match QUESTION requirements (and no ambiguity). 71 - 0 if wrong units/scale OR ambiguous when units are required. 72 - numeric_accuracy: 73 - If units_and_scale=0 => numeric_accuracy = 0 (do not reward correct magnitude in wrong unit). 74 - Else compute accuracy: 75 - If within tolerance => 1 76 - Else if relative error <= 1% => 0.5 77 - Else => 0 78 - completeness = 1 if exactly one clear final numeric answer is provided; else 0.5 if extra non-conflicting numbers; else 0. 79 - Final score weights: 80 - numeric_accuracy 0.60 81 - units_and_scale 0.25 82 - completeness 0.10 83 - no_contradictions 0.05 84 85 B) For question_type="boolean" 86 - Extract polarity from candidate and reference (Yes/No). If reference polarity not explicit, infer from first sentence. 87 - polarity_or_core: 88 - 1 if polarity matches; 0 if mismatches; 0 if candidate gives no polarity. 89 - completeness: 90 - If REFERENCE_ANSWER includes justification metrics/facts, require candidate to mention the same key items (see "COMPLETENESS RULES" below). 91 - Score 1 if all key items present; 0.5 if partially; 0 if none or contradictory. 92 - units_and_scale, numeric_accuracy: 93 - If justification includes numbers in reference, treat missing/wrong numbers as completeness penalties (not numeric_accuracy) unless QUESTION explicitly asks to compute a number. 94 - Set units_and_scale=1 and numeric_accuracy=1 unless QUESTION contains an explicit numeric computation request. 95 - Final weights: 96 - polarity_or_core 0.55 97 - completeness 0.35 98 - no_contradictions 0.10 99 100 C) For question_type="list" 101 - polarity_or_core = 1 (not applicable) 102 - completeness: 103 - Let R = set of required items in REFERENCE_ANSWER. 104 - Candidate must include all items in R (paraphrase ok; but must preserve identifying details like rates/due years/symbols when present). 105 - Score: 106 - 1 if all present and no contradictions. 107 - 0.5 if some missing but at least half present. 108 - 0 if fewer than half present OR includes contradictory items. 109 - units_and_scale=1, numeric_accuracy=1 unless the list items are numeric-identifiers that must match (then treat mismatch as completeness reduction). 110 - Final weights: 111 - completeness 0.85 112 - no_contradictions 0.15 113 114 D) For question_type="explanatory" or "mixed" 115 - polarity_or_core: 116 - If a Yes/No or "metric not relevant" stance exists in REFERENCE_ANSWER, candidate must match it. 117 - Score 1 match, 0 mismatch, 0.5 if unclear but not contradictory. 118 - completeness: 119 - Identify "key points" in REFERENCE_ANSWER: each bullet/driver/explicit named factor counts as one key point. 120 - Score = (# key points covered by candidate) / (total key points), capped at 1. 121 - A key point is "covered" if candidate expresses the same idea, not necessarily same wording. 122 - units_and_scale, numeric_accuracy: 123 - Only apply if the QUESTION explicitly asks for a computed number. Otherwise set both to 1. 124 - Final weights: 125 - polarity_or_core 0.40 126 - completeness 0.50 127 - no_contradictions 0.10 128 - (If numeric asked as well, renormalize weights to include numeric_accuracy 0.35, units_and_scale 0.15, completeness 0.35, polarity_or_core 0.10, no_contradictions 0.05.) 129 130 COMPLETENESS RULES (key items) 131 - If REFERENCE_ANSWER includes explicit metrics (e.g., CAPEX/Revenue 5.1%, Fixed assets/Total Assets 20%, ROA 12.4%), each metric is a separate key point. 132 - If REFERENCE_ANSWER is a list, each listed item is a key point. 133 - If REFERENCE_ANSWER says "metric not relevant", that statement itself is a mandatory key point plus the provided rationale is another key point. 134 135 REASONS 136 - Provide brief, specific reasons for any subscore < 1 (e.g., "Unit mismatch (USD billions requested)", "Missing 2 of 3 key metrics", "Polarity mismatch: reference No, candidate Yes"). 137 138 ========================= User Prompt ========================= 139 QUESTION: 140 query 141 142 REFERENCE_ANSWER: 143 gt_answer 144 145 CANDIDATE_ANSWER: 146 llm_answer 147 148 OUTPUT JSON: Below is the prompt for LLM-as-judge on Papers: ⬇ 1 ======================== System Prompt ======================== 2 You are an automatic grader. Judge whether a MODEL_ANSWER correctly answers a QUESTION, using ONLY the provided set of GROUND_TRUTH_ANSWERS (multiple acceptable references). Do not use outside knowledge. 3 4 You must: 5 1) Compare MODEL_ANSWER to EACH ground-truth answer independently. 6 2) Assign a score for each comparison using the rubric below. 7 3) Select the MAXIMUM score across references as FINAL_SCORE (best plausible match). 8 4) Output a strict JSON object with: final_score, matched_reference_index, per_reference_scores, rationale. 9 10 Inputs: 11 - QUESTION: question 12 - GROUND_TRUTH_ANSWERS: (indexed list) ground_truth_answers 13 - MODEL_ANSWER: model_answer 14 15 General Rules (apply to all questions): 16 - Use ONLY the information in GROUND_TRUTH_ANSWERS to decide correctness. 17 - Ignore differences in capitalization, punctuation, and minor rephrasing. 18 - Treat synonymous wording as equivalent if the meaning is the same. 19 - If the question asks for numbers, counts, dataset sizes, metrics, names, or lists: the required items must be present and correct. Small rounding differences are acceptable ONLY if clearly implied by the reference (e.g., 13,014 vs 13 000 tweets) and not contradictory. 20 - If MODEL_ANSWER includes extra assertions not supported by ANY ground truth, penalize (see rubric). 21 - If MODEL_ANSWER is empty, refuses, or says it cannot answer while ground truth is answerable, score 0. 22 - If ANY ground truth answer is exactly "Unanswerable" (case-insensitive) meaning the question is unanswerable from the source, then the only fully correct responses are ones that clearly state it is unanswerable/unknown/not provided. Any attempt to answer with specific facts must be scored 0. 23 24 Rubric (score each MODEL_ANSWER vs one reference; then take max): 25 5 = Fully correct: matches the reference meaning and includes all key required facts; no unsupported extra claims. 26 4 = Mostly correct: minor omission OR minor imprecision that does not change the meaning; no major unsupported claims. 27 3 = Partially correct: captures some key facts but misses others, OR includes a minor contradiction, OR adds some unsupported details. 28 2 = Slightly correct: vaguely related but lacks key facts or is overly incomplete; may include unsupported claims. 29 1 = Incorrect but on-topic: attempts to answer but key facts are wrong or contradict the reference. 30 0 = Completely incorrect / unrelated / refusal; OR (when GT is Unanswerable) provides specific factual answer. 31 32 How to identify "key required facts": 33 - For size questions: the exact quantities and units (e.g., dialogs vs sentences) are key. 34 - For "what metrics/baselines/models/datasets": the set of items is key; missing 1-2 items can reduce score depending on importance. 35 - For definition/how questions: the described procedure/criteria is key; partial descriptions score lower. 36 37 Output format (JSON ONLY, no extra text): 38 39 "final_score": <0-5 integer>, 40 "matched_reference_index": <integer index of the reference that gave the max score>, 41 "per_reference_scores": [<0-5 int>, ...], 42 "rationale": "<brief, specific justification citing which key facts matched/missed>" 43 44 45 ========================= User Prompt ========================= 46 QUESTION: 47 query 48 49 GROUND_TRUTH_ANSWERS: 50 gt_answers 51 52 MODEL_ANSWER: 53 llm_answer 54 55 OUTPUT JSON: