Building an AI-powered contract intelligence platform with Amazon Quick and Amazon Bedrock AgentCore
https://aws.amazon.com/blogs/machine-learning/building-an-ai-powered-contract-intelligence-platform-with-amazon-quick-and-amazon-bedrock-agentcore/📌 AWS 合約智慧平臺:RAG 為何算不出合約總金額
TL;DR:RAG 擅長回答單一合約問題,卻算不出「250 份合約總值多少」,AWS 改用結構化萃取加雙模型驗證解決。
假設你手上有 250 份供應商合約,每份 10 到 20 頁,加總起來上看 5,000 頁非結構化資料。主管隨口問一句「我們花最多錢的供應商是誰」,你要嘛派人一份份翻閱、抄進試算表,要嘛把整批 PDF 丟給市面上的 AI 聊天工具問答。後者聽起來很誘人,答案也來得又快又篤定,卻常常是錯的。
🤔 問題不在提示詞,而在架構本身
AWS 在部落格中指出,這個錯誤答案不是偶然,而是內建在多數 AI 問答工具的運作方式裡。這些工具內部把每份文件切成一段段文字並向量化,存進知識庫;使用者提問時,系統只取回與問題最相關的 top-k 段落,再用這些段落組出答案。對於「AnyCompany 合約的付款條件是什麼」這類單點查詢,這套機制運作得很好,正確段落會被準確撈出。但換成「250 份合約的總值是多少」這種橫跨整個組合的聚合問題,系統依然只回傳 top-k 段落,並只針對這些段落做加總,因為完整的合約組合根本沒有被放進模型的上下文裡。這不是某個工具做得不夠好,而是 Retrieval Augmented Generation(RAG)機制本身的局限:更好的提示詞救不了它,需要的是不同的架構。
🧩 用結構化萃取取代單純檢索
AWS 團隊的解法是:把合約裡的關鍵欄位先萃取成結構化資料存進資料庫,再交給專門做分析的工具去查詢與計算,讓 AI 負責處理「非結構化轉結構化」,資料庫負責處理「數學」。同時保留原始文件建立知識庫,供單一合約問答使用,達成「橫跨整個組合的聚合問題」與「精準的單一文件查詢」兩者兼顧。
整套流程用 Strands Agent SDK 建構,部署在 Amazon Bedrock AgentCore 的 runtime 上,由 AgentCore 負責無伺服器(serverless)託管、自動擴縮與 session 隔離,AI 元件本身不需要維運任何基礎設施。透過 Amazon Bedrock AgentCore 的 Policy 功能,團隊以 Cedar-based 政策定義安全控管邊界,在執行前先以自動化推理驗證,確保合約定價條款、財務承諾、供應商關係等敏感資訊只有被授權的 agent 與使用者才能存取。
核心是雙模型設計:一個模型負責萃取欄位,另一個獨立模型負責驗證。兩個獨立模型互相不同意,本身就是一個「該交給人類覆核」的強訊號,比單一模型自信滿滿地產出幻覺數值要安全得多。團隊在測試中發現一個很具體的失敗模式:驗證模型有時會以 95% 到 100% 的信心把某份合約標記為「已簽署」,但實際上根本沒有簽名,原因是模型把「簽名欄位」本身(例如「Signature: __________」這樣的空白欄)誤判成簽名已存在的證據。團隊沒有選擇用更精巧的提示詞硬凹過去,而是引入 Amazon Textract 的電腦視覺簽名偵測作為架構上的仲裁者:Textract 靠視覺分析而非語言理解來判斷頁面上是否真的有手寫或數位簽名,且只在兩個模型意見分歧時才啟動,藉此把成本控制在最低,同時抓住這種假陽性。這說明了一個實務上很值得參考的分工原則:LLM 適合處理文件理解、欄位萃取、上下文判讀;視覺元素偵測、精確計數、數學運算則交給確定性(deterministic)服務去做。
團隊也拿一組 20 份合約的樣本資料,人工標註全部 8 個欄位(總計 160 筆數值)建立 ground truth,用來比較不同萃取模型與驗證模型組合的表現,藉此決定最終要採用哪一種模型搭配。
⚠️ 模型會變,架構思路才是重點
AWS 在文中特別提醒,文中提到的模型是解決方案建置當下可用的版本,模型選項變化很快,讀者若要參考落地,應該以自己當下能取得的模型重新測試,而不是照搬文中的模型組合。
🎯 實務啟示
當你的 AI 應用場景需要「跨文件聚合」而不只是「單點查詢」時,先問自己一個問題:答案是不是需要對整個資料集做加總、計數或比較?如果是,單純加大 RAG 的 top-k 或寫更精巧的提示詞多半沒有用,真正該做的是把非結構化資料先萃取成結構化欄位,讓資料庫或分析工具去處理數學運算,同時用雙模型互相校驗、搭配確定性服務仲裁分歧,把 LLM 的幻覺風險關進一個可控的範圍裡。
🔗 來源
- 標題:Building an AI-powered contract intelligence platform with Amazon Quick and Amazon Bedrock AgentCore
- 作者/機構:Konala McGrath, AWS ML
- 連結:https://aws.amazon.com/blogs/machine-learning/building-an-ai-powered-contract-intelligence-platform-with-amazon-quick-and-amazon-bedrock-agentcore/
#AWS #BedrockAgentCore #RAG #AIAgents #ContractIntelligence #StrandsAgentSDK #AmazonTextract #StructuredExtraction #LLM #EnterpriseAI
原始資料 AWS ML · 收集於 2026-09-29
摘要原文
You’re a director of contracting, responsible for hundreds, maybe thousands, of vendor contracts. Each one is packed with critical data: contract values, expiration dates, signing status, and key contacts. With that information locked inside PDFs, you and your team spend hours manually extracting it, maintaining spreadsheets, and fielding the same recurring questions: “Which vendor are we spending the most with?” or “Which contracts are about to expire?” So you turn to AI chat tools and enterprise Q&A solutions. You upload a contract, ask questions in natural language, and for a single document, or even a handful, it genuinely works well. The real challenge shows up at scale, across hundreds of contracts. Most of these tools rely on a technique called Retrieval Augmented Generation (RAG). RAG breaks long text into chunks and indexes each one individually. During a search, RAG retrieves only the top-k chunks of text most relevant to a question, an approach more widely known as semantic search. That’s fine when the answer lives in one place. But when a question spans every contract, like total exposure or upcoming renewals, semantic search falls short. The answer requires aggregation across the full dataset, not only a handful of chunks. A better prompt won’t fix this. A different architecture will. In this post, we share the architecture behind a contract intelligence platform on AWS. It extracts contract data with AI agents, verifies accuracy with a multi-model approach, and delivers instant answers through embedded analytics and natural language querying. Everything runs from a single web application. Say your portfolio holds 250 vendor contracts, and leadership keeps asking the same four questions: These are basic questions, but the answers are buried. Each of your 250 contracts runs 10–20 pages, so that’s up to 5,000 pages of unstructured data. To answer those questions, an analyst opens each PDF, searches for the fields that matter, and copies the values into a spreadsheet, then repeats the process 250 times. That’s more than a week of effort to clear the backlog, before a single new contract arrives. Every follow-up question from leadership means another round of filtering and analysis. Each round risks working from stale data or breaking hardcoded formulas on the new data. So you upload the portfolio to one of the leading AI chat tools and ask for the total value. The answer comes back fast, confident, and wrong. That wrong answer wasn’t a fluke. It’s baked into how these tools are built. Internally they chunk each document into vectors and store them in a knowledge base. When you ask a question, they pull back the top-k chunks that best match it, then build an answer using only those chunks as context. For a targeted lookup, that’s exactly what you want. Ask “What are the payment terms in the AnyCompany contract?” and the right chunk surfaces with a clean answer. A portfolio question works against that mechanism instead of with it. When you ask, “What’s the total contract value across all 250 contracts?”, the system still returns only the top-k chunks and totals only those. It can’t sum, count, or compare across the portfolio because the portfolio never lands in front of the model. It isn’t a flaw in any one tool but in how RAG itself works. The answer is structured extraction, not better retrieval. To answer aggregation questions across hundreds of documents, you extract the key fields into a database, then query them with analytics tools built for exactly that. AI handles the unstructured-to-structured conversion at scale, and the database is used for math. You keep the original documents in a knowledge base for the single-contract questions it handles well. The result is a system that answers both kinds of questions: portfolio-wide aggregates and precise single-document lookups. The platform is a React web application on AWS that turns a portfolio of contract PDFs into structured, queryable data. AI agents extract the key fields from each contract and independently verify them, with Amazon Textract settling any signature disagreements. Users then explore the results through embedded dashboards and a natural language chat agent, getting both portfolio-wide answers and single-contract details. The pipeline works as follows: The entire pipeline can process a contract in seconds under typical conditions, and the serverless architecture is designed to help scale to handle many contracts in parallel. Here is the reference architecture for this solution. Figure 1: Contract intelligence pipeline, from ingestion to query Note: This post references the language models available when the solution was built. Model options change quickly, use the models available to you and re-test the solution before relying on the results. The pipeline turns each uploaded contract into verified, structured data. It starts with two agents, one that extracts the fields and one that independently checks them, both running on fully managed infrastructure. The following section covers how they work together and the models behind them. The extraction and verification agents are built with the Strands Agent SDK and deployed on AgentCore runtime, a capability of Amazon Bedrock AgentCore. The Strands Agent SDK is an open-source, model-driven framework for building autonomous agents. AgentCore handles serverless hosting, automatic scaling, and session isolation, so there’s no infrastructure to manage for the AI components. With Policy in Amazon Bedrock AgentCore , you can define and enforce security controls as a protective boundary around agent operations. This securely handles sensitive data such as pricing terms, financial commitments, and vendor relationships. Cedar-based policies exist outside agent code, and you can validate them with automated reasoning before enforcement. Agents and users only access the contracts they are authorized to see. We deliberately chose two different foundation models for extraction and verification: For model availability by Region, refer to Supported models by AWS Region in Amazon Bedrock. This dual-model pattern is key to high accuracy on contract data, where mistakes are costly. A single model might hallucinate a value with high confidence. Two independent models disagreeing is a strong signal that human review is needed. During testing, we found a revealing failure mode. The verification model would sometimes flag a contract as “signed” with 95–100% confidence when no signature existed, disagreeing with the extractor, which had correctly read it as unsigned. The model misread empty signature blocks, treating the presence of a signature field (“Signature: __________”) as proof of a signature. Rather than accepting this hallucination or writing elaborate prompts to work around it, we added Amazon Textract computer-vision-based signature detection as an architectural tiebreaker. Amazon Textract uses visual analysis, not language understanding, to detect actual handwritten or digital signatures on the page. It runs only when the two models disagree on the is_signed field, which keeps costs minimal while catching the false positives. This illustrates an important pattern: use large language models (LLMs) for what they excel at (document comprehension, field extraction, contextual understanding) and deterministic services for what they struggle with (visual element detection, precise counting, mathematical operations). The pipeline’s accuracy depends most on the model that handles extraction, so we tested several extractor and verifier combinations before settling on one. Using our 20-contract sample dataset, we hand-labeled all 8 fields (160 values total) to establish ground truth, then measured how closely each combination matched it. The evaluation surfaced two patterns. Extraction is the higher-impact step.
由 claude-code/sonnet 自動生成