关于 document-extraction
面向 ServiceNow Document Intelligence 的技能,用于配置从文档中提取结构化字段的流程。支持模板、字段映射、按置信度审核、验证和更正,适用于文档处理工作流。
主要功能
- 01配置文档提取模板
- 02将提取字段映射到表列
- 03提交并监控提取请求
- 04检查置信度和验证结果
- 05更正结果并填充目标记录
适用场景
- 01批量处理发票
- 02提取合同元数据
- 03将表单数字化为 ServiceNow 记录
- 04审核低置信度的提取字段
MCP 相关
使用 ServiceNow MCP 工具管理模板、字段映射、提取请求和结果,并创建或更新目标记录。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ happy-technologies-llc/ happy-platform-skills --skill document-extraction安装后在 Claude Code 中输入/document-extraction确认已加载。
详细介绍
文档提取
概述
此技能提供了一套结构化方法,用于使用 ServiceNow Document Intelligence 从文档中提取结构化数据。它可以帮助你:
- 在
sn_doc_template中配置和管理不同文档类型(发票、合同、表单、采购订单)的提取模板 - 通过
sn_doc_intelligence_extraction管道提交文档进行提取 - 在
sn_doc_intelligence_field_map中定义字段映射,将提取的数据映射到 ServiceNow 表字段 - 检查并验证
sn_doc_intelligence_extraction_result中的提取结果 - 设置验证规则,确保数据质量并标记置信度较低的提取结果
- 处理提取失败,并重新训练模型以提升准确性
适用场景: 当你需要大规模处理文档(批量处理发票、提取合同元数据、表单数字化)、从文档中手动录入数据容易出错或耗时较长,或需要建立新的文档处理管道时。
所需插件: com.sn_doc_intelligence
前提条件
- 角色:
sn_doc_intelligence_admin、sn_doc_intelligence_user或admin - 访问权限: 对
sn_doc_intelligence_extraction、sn_doc_template、sn_doc_intelligence_field_map和sys_attachment表具有读写权限 - 知识: 了解待处理的文档类型、字段布局,以及用于存储提取数据的目标 ServiceNow 表
- 插件: 必须激活 Document Intelligence(
com.sn_doc_intelligence) - 文档: 源文档必须采用支持的格式(PDF、PNG、JPG、TIFF)
操作步骤
第 1 步:查看可用的提取模板
检查实例中已配置的文档提取模板。
使用 MCP(Claude Code/Desktop):
Tool: SN-Query-Table
Parameters:
table_name: sn_doc_template
query: active=true
fields: sys_id,name,description,document_type,target_table,state,extraction_model,confidence_threshold,field_count
limit: 50
order_by: name
使用 REST API:
GET /api/now/table/sn_doc_template?sysparm_query=active=true^ORDERBYname&sysparm_fields=sys_id,name,description,document_type,target_table,state,extraction_model,confidence_threshold,field_count&sysparm_limit=50&sysparm_display_value=true
常见模板类型:
| 文档类型 | 目标表 | 用途 |
|---|---|---|
| 发票 | sn_proc_invoice | 应付账款发票处理 |
| 采购订单 | proc_po | 采购订单数据录入 |
| 合同 | ast_contract | 合同元数据提取 |
| W-9 / 纳税表 | core_company | 供应商税务信息 |
| 身份证件 | sys_user | 身份验证 |
| 保险凭证 | ast_contract | COI 跟踪 |
| 工单 | wm_order | 现场服务文档 |
第 2 步:创建或配置提取模板
如果尚无适用于文档类型的模板,请创建一个。
使用 MCP:
Tool: SN-Create-Record
Parameters:
table_name: sn_doc_template
fields:
name: "Vendor Invoice Template"
description: "Extracts header and line-item data from vendor invoices for accounts payable processing"
document_type: invoice
target_table: sn_proc_invoice
confidence_threshold: 0.85
active: true
state: draft
使用 REST API:
POST /api/now/table/sn_doc_template
Content-Type: application/json
{
"name": "Vendor Invoice Template",
"description": "Extracts header and line-item data from vendor invoices",
"document_type": "invoice",
"target_table": "sn_proc_invoice",
"confidence_threshold": "0.85",
"active": "true",
"state": "draft"
}
第 3 步:定义字段映射
为每个提取模板将文档字段映射到 ServiceNow 表列。
使用 MCP:
Tool: SN-Create-Record
Parameters:
table_name: sn_doc_intelligence_field_map
fields:
template: [template_sys_id]
source_field: "Invoice Number"
target_table: sn_proc_invoice
target_field: number
field_type: string
required: true
validation_regex: "^INV-[0-9]{4,10}$"
order: 100
对每个字段映射重复此操作:
| 源字段(文档) | 目标字段(表) | 类型 | 必填 | 验证 |
|---|---|---|---|---|
| 发票编号 | number | 字符串 | 是 | 匹配模式 |
| 发票日期 | invoice_date | 日期 | 是 | 日期有效 |
| 到期日 | due_date | 日期 | 是 | 晚于发票日期 |
| 供应商名称 | vendor | 引用 | 是 | 匹配 core_company |
| PO 编号 | po_number | 字符串 | 否 | 匹配 proc_po |
| 小计 | subtotal | 货币 | 是 | 正数 |
| 税额 | tax | 货币 | 否 | 非负数 |
| 总金额 | invoice_amount | 货币 | 是 | subtotal + tax |
| 行项目描述 | line_items.description | 字符串 | 是 | 非空 |
| 行项目数量 | line_items.quantity | 整数 | 是 | 正整数 |
| 行项目单价 | line_items.unit_price | 货币 | 是 | 正数 |
使用 REST API:
POST /api/now/table/sn_doc_intelligence_field_map
Content-Type: application/json
{
"template": "[template_sys_id]",
"source_field": "Invoice Number",
"target_table": "sn_proc_invoice",
"target_field": "number",
"field_type": "string",
"required": "true",
"validation_regex": "^INV-[0-9]{4,10}$",
"order": "100"
}
第 4 步:提交文档进行提取
创建提取请求,通过管道处理文档。
使用 MCP:
Tool: SN-Create-Record
Parameters:
table_name: sn_doc_intelligence_extraction
fields:
template: [template_sys_id]
source_document: [attachment_sys_id]
document_type: invoice
state: submitted
priority: 3
requested_by: [user_sys_id]
short_description: "Extract data from vendor invoice INV-2026-0456"
使用 REST API:
POST /api/now/table/sn_doc_intelligence_extraction
Content-Type: application/json
{
"template": "[template_sys_id]",
"source_document": "[attachment_sys_id]",
"document_type": "invoice",
"state": "submitted",
"priority": "3",
"requested_by": "[user_sys_id]",
"short_description": "Extract data from vendor invoice INV-2026-0456"
}
如需批量处理,请提交多个文档:
# Iterate over attachments and create extraction records
for attachment_id in [list_of_attachment_sys_ids]; do
curl -X POST "https://[instance].service-now.com/api/now/table/sn_doc_intelligence_extraction" \
-H "Content-Type: application/json" \
-d "{\"template\":\"[template_sys_id]\",\"source_document\":\"$attachment_id\",\"document_type\":\"invoice\",\"state\":\"submitted\"}"
done
步骤 5:监控提取进度
跟踪已提交提取请求的状态。
使用 MCP:
Tool: SN-Query-Table
Parameters:
table_name: sn_doc_intelligence_extraction
query: state=submitted^ORstate=processing^ORstate=review
fields: sys_id,number,short_description,state,template,document_type,source_document,confidence_score,sys_created_on,error_message
limit: 50
order_by: sys_created_on
使用 REST API:
GET /api/now/table/sn_doc_intelligence_extraction?sysparm_query=state=submitted^ORstate=processing^ORstate=review^ORDERBYDESCsys_created_on&sysparm_fields=sys_id,number,short_description,state,template,document_type,source_document,confidence_score,sys_created_on,error_message&sysparm_limit=50&sysparm_display_value=true
步骤 6:检查提取结果
检查提取的数据以及每个字段的置信度分数。
使用 MCP:
Tool: SN-Query-Table
Parameters:
table_name: sn_doc_intelligence_extraction_result
query: extraction=[extraction_sys_id]
fields: sys_id,field_name,extracted_value,confidence_score,validation_status,mapped_field,needs_review
limit: 100
order_by: order
使用 REST API:
GET /api/now/table/sn_doc_intelligence_extraction_result?sysparm_query=extraction=[extraction_sys_id]^ORDERBYorder&sysparm_fields=sys_id,field_name,extracted_value,confidence_score,validation_status,mapped_field,needs_review&sysparm_limit=100&sysparm_display_value=true
根据以下阈值评估结果:
| 置信度级别 | 所需操作 |
|---|---|
| >= 0.95 | 自动接受;无需审核 |
| 0.85 - 0.94 | 接受并抽查 |
| 0.70 - 0.84 | 需要人工审核 |
| < 0.70 | 标记为重新提取或手动录入 |
步骤 7:验证并更正提取的数据
对于需要审核的字段,请更新提取结果。
使用 MCP:
Tool: SN-Update-Record
Parameters:
table_name: sn_doc_intelligence_extraction_result
sys_id: [result_sys_id]
data:
extracted_value: "INV-2026-0456"
validation_status: validated
needs_review: false
reviewer_notes: "Corrected invoice number; OCR misread '0' as 'O'"
使用 REST API:
PATCH /api/now/table/sn_doc_intelligence_extraction_result/[result_sys_id]
Content-Type: application/json
{
"extracted_value": "INV-2026-0456",
"validation_status": "validated",
"needs_review": "false",
"reviewer_notes": "Corrected invoice number; OCR misread '0' as 'O'"
}
步骤 8:完成提取并填充目标记录
验证所有字段后,将提取标记为完成,并创建或更新目标记录。
使用 MCP:
Tool: SN-Update-Record
Parameters:
table_name: sn_doc_intelligence_extraction
sys_id: [extraction_sys_id]
data:
state: completed
work_notes: "Extraction validated. 12/14 fields auto-accepted (>95% confidence). 2 fields manually corrected. Target record created in sn_proc_invoice."
使用提取的数据创建目标记录:
Tool: SN-Create-Record
Parameters:
table_name: sn_proc_invoice
fields:
number: "INV-2026-0456"
vendor: [vendor_sys_id]
invoice_date: "2026-03-15"
due_date: "2026-04-14"
invoice_amount: "15750.00"
po_number: "PO0012345"
state: pending
source: document_intelligence
work_notes: "Record created via Document Intelligence extraction [extraction_number]"
使用 REST API:
PATCH /api/now/table/sn_doc_intelligence_extraction/[extraction_sys_id]
Content-Type: application/json
{
"state": "completed",
"work_notes": "Extraction validated. Target record created."
}
工具用法
MCP 工具参考
| 工具 | 适用场景 |
|---|---|
SN-Natural-Language-Search | 根据描述查找提取记录或模板 |
SN-Query-Table | 查询模板、提取记录、结果和字段映射 |
SN-Get-Record | 获取特定的提取记录或模板记录 |
SN-Create-Record | 创建模板、字段映射和提取请求 |
SN-Update-Record | 更新提取状态、验证结果并更正数据 |
SN-Add-Work-Notes | 记录提取结果和处理备注 |
REST API 参考
| 端点 | 方法 | 用途 |
|---|---|---|
/api/now/table/sn_doc_template | GET/POST | 查询或创建提取模板 |
/api/now/table/sn_doc_intelligence_field_map | GET/POST | 查询或创建字段映射 |
/api/now/table/sn_doc_intelligence_extraction | GET/POST/PATCH | 管理提取请求 |
/api/now/table/sn_doc_intelligence_extraction_result | GET/PATCH | 检查并更正提取结果 |
/api/now/table/sys_attachment | GET | 查询文档附件 |
/api/now/attachment/{sys_id}/file | GET | 下载源文档 |
最佳实践
- 每种文档类型使用一个模板: 为每种文档格式创建单独的模板;对于高处理量的供应商,使用供应商专属模板的表现会优于为所有发票使用单一模板
- 设置合适的阈值: 从 0.85 的置信度阈值开始,并根据错误率进行调整;较低的阈值可提高处理量,但需要更多人工审核
- 训练数据: 每个模板至少提供 20-30 份示例文档,以获得最佳提取准确率
- 验证规则: 使用正则表达式模式、引用查找和跨字段验证(例如,总额 = 小计 + 税额),自动发现提取错误
- 批量处理: 在非高峰时段分批提交文档,避免影响实例性能
- 监控准确率: 长期跟踪提取准确率指标;准确率低于 90% 时重新训练模型
- 处理异常: 在
sn_doc_intelligence_task中为提取失败的文档创建提取任务,并将其分配给数据录入人员 - 安全处理: 确保文档附件符合数据保留政策;处理完成后删除临时提取产物
故障排除
“未找到提取模板”
原因: 模板未启用,或文档类型不匹配
解决方案: 使用 active=true 查询 sn_doc_template,查看可用模板。确认 document_type 字段与提交内容相匹配。
“所有字段的置信度都偏低”
原因: 文档质量较差(分辨率低、扫描件倾斜、文本为手写)或模板不匹配
解决方案: 检查文档分辨率(OCR 的最低要求为 300 DPI)。确认文档布局与模板预期一致。对于非标准格式,可考虑创建新模板。
“字段映射验证失败”
原因: 提取的值与验证正则表达式或目标字段类型不匹配
解决方案: 检查 sn_doc_intelligence_field_map 中的验证规则。调整正则表达式,以适应合理的差异(例如,不同供应商使用的发票编号格式各不相同)。
“提取卡在处理中状态”
原因: Document Intelligence 引擎超时或处理队列积压
解决方案: 检查 sn_doc_intelligence_extraction 记录中的错误消息。确认 Document Intelligence 引擎正在运行:导航至 Document Intelligence > Dashboard。如有需要,请重新提交提取任务。
“存在重复的提取记录”
原因: 同一文档被提交多次
解决方案: 提交前,使用 source_document=[attachment_sys_id]^state!=failed 查询 sn_doc_intelligence_extraction,检查是否已有提取记录。
示例
示例 1:发票数据提取
输入: 上传到 ServiceNow 的 Acme Corp PDF 发票
流程:
- 识别模板:“Vendor Invoice Template”(sys_id:abc123)
- 使用附件引用提交提取任务
- 结果:提取了 14 个字段,平均置信度为 0.92
- 有 2 个字段低于阈值:采购订单编号(0.78)、行项目描述(0.81)
- 人工审核确认采购订单编号正确,并修正行项目描述
- 在
sn_proc_invoice中创建目标发票记录
示例 2:合同元数据提取
输入: 供法律审核的已签署 MSA PDF
流程:
Tool: SN-Create-Record
Parameters:
table_name: sn_doc_intelligence_extraction
fields:
template: [contract_template_sys_id]
source_document: [attachment_sys_id]
document_type: contract
state: submitted
short_description: "Extract metadata from Acme Corp MSA"
提取的字段: 合同双方、生效日期、期限、总金额、管辖法律、自动续约标记、通知期限。自动填充 ast_contract 记录。
示例 3:批量处理税务表单
输入: 为供应商入驻上传的 50 份 W-9 表单
流程:
- 查询所有未处理的 W-9 附件
- 使用 W-9 模板提交批量提取任务
- 监控结果:47 份成功提取,3 份需要人工审核(手写内容)
- 在
core_company中创建供应商记录,并填入提取的 TIN、法定名称和地址 - 通过
sn_doc_intelligence_task将 3 个异常项分派给数据录入团队
批量状态查询:
Tool: SN-Query-Table
Parameters:
table_name: sn_doc_intelligence_extraction
query: template=[w9_template_sys_id]^sys_created_on>=2026-03-19
fields: sys_id,number,state,confidence_score,error_message
limit: 50
相关技能
document/smart-documents- 管理文档模板、版本控制和自动生成legal/contract-analysis- 分析提取的合同数据,识别风险和条款legal/contract-obligation-extraction- 从合同文档中提取义务procurement/invoice-management- 通过应付账款工作流处理提取的发票数据development/data-import- 将提取的数据批量导入 ServiceNow 表