GLM-OCR Table Recognition Skill / GLM-OCR 表格识别技能
Extract tables from images and PDFs and convert them to Markdown format using the ZhiPu GLM-OCR layout parsing API.
When to Use / 使用场景
- - Extract tables from images or scanned documents / 从图片或扫描件中提取表格
- Convert table images to Markdown or Excel format / 将表格图片转为 Markdown 或可编辑格式
- Recognize complex tables with merged cells / 识别含合并单元格的复杂表格
- Parse financial statements, invoices, reports with tables / 解析财务报表、发票、带表格的报告
- User mentions "extract table", "recognize table", "表格识别", "提取表格", "表格OCR", "表格转文字"
Key Features / 核心特性
- - Complex table support: Handles merged cells, nested tables, multi-row headers
- Markdown output: Tables are output in clean Markdown format, easy to edit and convert
- Multi-page PDF: Supports batch extraction from multi-page PDF documents
- Local file & URL: Supports both local files and remote URLs
Resource Links / 资源链接
Layout Parsing / 版面解析 |
Prerequisites / 前置条件
API Key Setup / API Key 配置(Required / 必需)
脚本通过 ZHIPU_API_KEY 环境变量获取密钥,可与其他智谱技能复用同一个 key。
This script reads the key from the ZHIPU_API_KEY environment variable. Reusing the same key across Zhipu skills is optional.
Get Key / 获取 Key: Visit 智谱开放平台 API Keys to create or copy your key.
Setup options / 配置方式(任选一种):
- 1. Global config (recommended) / 全局配置(推荐): Set once in
openclaw.json under env.vars, all Zhipu skills will share it:
CODEBLOCK0
- 2. Skill-level config / Skill 级别配置: Set for this skill only in
openclaw.json:
CODEBLOCK1
- 3. Shell environment variable / Shell 环境变量: Add to
~/.zshrc:
CODEBLOCK2
💡 如果你已为其他智谱 skill(如 glmocr、glmv-caption、glm-image-generation)配置过 key,它们共享同一个 ZHIPU_API_KEY,无需重复配置。
Security & Transparency / 安全与透明度
- - Environment variables used / 使用的环境变量:
-
ZHIPU_API_KEY (required / 必需)
-
GLM_OCR_TIMEOUT (optional timeout seconds / 可选超时秒数)
- - Fixed endpoint / 固定官方端点: INLINECODE12
- No custom API URL override / 不支持自定义 API URL 覆盖: this avoids accidental key exfiltration via redirected endpoints.
- Raw upstream response is optional / 原始响应默认不返回: use
--include-raw only when needed for debugging.
⛔ MANDATORY RESTRICTIONS / 强制限制 ⛔
- 1. ONLY use GLM-OCR API — Execute the script INLINECODE14
- NEVER parse tables yourself — Do NOT try to extract tables using built-in vision or any other method
- NEVER offer alternatives — Do NOT suggest "I can try to recognize it" or similar
- IF API fails — Display the error message and STOP immediately
- NO fallback methods — Do NOT attempt table extraction any other way
📋 Output Display Rules / 输出展示规则
After running the script, present the OCR result clearly and safely.
- - Show extracted table Markdown (
text) in full - Summarization is allowed, but do not hide important extraction failures
- If
layout_details contains table-related entries, you may highlight them - If the result file is saved, tell the user the file path
- Show raw upstream response only when explicitly requested or debugging (
--include-raw)
How to Use / 使用方法
Extract from URL / 从 URL 提取
CODEBLOCK3
Extract from Local File / 从本地文件提取
CODEBLOCK4
Save Result to File / 保存结果到文件
CODEBLOCK5
Include Raw Upstream Response (Debug Only) / 包含原始上游响应(仅调试)
CODEBLOCK6
CLI Reference / CLI 参数
CODEBLOCK7
| Parameter | Required | Description |
|---|
| INLINECODE18 | One of | URL to image/PDF |
| INLINECODE19 |
One of | Local file path to image/PDF |
|
--output,
-o | No | Save result JSON to file |
|
--pretty | No | Pretty-print JSON output |
|
--include-raw | No | Include raw upstream API response in
result field (debug only) |
Response Format / 响应格式
CODEBLOCK8
Key fields:
- -
ok — whether extraction succeeded - INLINECODE26 — extracted text in Markdown (use this for display)
- INLINECODE27 — layout analysis details
- INLINECODE28 — error details on failure
Error Handling / 错误处理
API key not configured:
CODEBLOCK9
→ Show exact error to user, guide them to configure
Authentication failed (401/403): API key invalid/expired → reconfigure
Rate limit (429): Quota exhausted → inform user to wait
File not found: Local file missing → check path
GLM-OCR Table Recognition Skill / GLM-OCR 表格识别技能
使用智谱GLM-OCR版面解析API从图片和PDF中提取表格并转换为Markdown格式。
When to Use / 使用场景
- - 从图片或扫描件中提取表格
- 将表格图片转为Markdown或可编辑格式
- 识别含合并单元格的复杂表格
- 解析财务报表、发票、带表格的报告
- 用户提及提取表格、识别表格、表格识别、表格OCR、表格转文字
Key Features / 核心特性
- - 支持复杂表格:处理合并单元格、嵌套表格、多行表头
- Markdown输出:表格以整洁的Markdown格式输出,易于编辑和转换
- 多页PDF支持:支持从多页PDF文档批量提取
- 本地文件和URL:支持本地文件和远程URL
Resource Links / 资源链接
版面解析 |
Prerequisites / 前置条件
API Key Setup / API Key 配置(必需)
脚本通过 ZHIPUAPIKEY 环境变量获取密钥,可与其他智谱技能复用同一个key。
获取密钥: 访问智谱开放平台 API Keys创建或复制你的密钥。
配置方式(任选一种):
- 1. 全局配置(推荐): 在 openclaw.json 的 env.vars 中设置一次,所有智谱技能共享:
json
{
env: {
vars: {
ZHIPUAPIKEY: 你的密钥
}
}
}
- 2. Skill级别配置: 仅在 openclaw.json 中为此技能配置:
json
{
skills: {
entries: {
glmocr-table: {
env: {
ZHIPUAPIKEY: 你的密钥
}
}
}
}
}
- 3. Shell环境变量: 添加到 ~/.zshrc:
bash
export ZHIPU
APIKEY=你的密钥
💡 如果你已为其他智谱skill(如 glmocr、glmv-caption、glm-image-generation)配置过密钥,它们共享同一个 ZHIPUAPIKEY,无需重复配置。
Security & Transparency / 安全与透明度
- ZHIPU
APIKEY(必需)
- GLM
OCRTIMEOUT(可选超时秒数)
- - 固定官方端点: https://open.bigmodel.cn/api/paas/v4/layout_parsing
- 不支持自定义API URL覆盖: 避免通过重定向端点泄露密钥。
- 原始上游响应默认不返回: 仅在调试需要时使用 --include-raw。
⛔ 强制限制 ⛔
- 1. 仅使用GLM-OCR API — 执行脚本 python scripts/glmocrcli.py
- 切勿自行解析表格 — 不要尝试使用内置视觉或其他方法提取表格
- 切勿提供替代方案 — 不要建议我可以尝试识别或类似说法
- 如果API失败 — 显示错误信息并立即停止
- 无备用方法 — 不要尝试以任何其他方式提取表格
📋 输出展示规则
运行脚本后,清晰安全地展示OCR结果。
- - 完整显示提取的表格Markdown(text)
- 允许总结,但不要隐藏重要的提取失败信息
- 如果 layout_details 包含表格相关条目,可以高亮显示
- 如果结果文件已保存,告知用户文件路径
- 仅在明确请求或调试时显示原始上游响应(--include-raw)
How to Use / 使用方法
从URL提取
bash
python scripts/glmocrcli.py --file-url https://example.com/table.png
从本地文件提取
bash
python scripts/glmocrcli.py --file /path/to/table.png
保存结果到文件
bash
python scripts/glmocrcli.py --file table.png --output result.json --pretty
包含原始上游响应(仅调试)
bash
python scripts/glmocrcli.py --file table.png --output result.json --include-raw
CLI Reference / CLI 参数
python {baseDir}/scripts/glmocrcli.py (--file-url URL | --file PATH) [--output FILE] [--pretty] [--include-raw]
| 参数 | 必需 | 描述 |
|---|
| --file-url | 二选一 | 图片/PDF的URL |
| --file |
二选一 | 图片/PDF的本地文件路径 |
| --output, -o | 否 | 将结果JSON保存到文件 |
| --pretty | 否 | 美化JSON输出格式 |
| --include-raw | 否 | 在result字段中包含原始上游API响应(仅调试) |
Response Format / 响应格式
json
{
ok: true,
text: | Column 1 | Column 2 |\n|----------|----------|\n| Data | Data |,
layout_details: [...],
result: null,
error: null,
source: /path/to/file,
source_type: file,
rawresultincluded: false
}
关键字段:
- - ok — 提取是否成功
- text — 提取的Markdown文本(用于展示)
- layout_details — 版面分析详情
- error — 失败时的错误详情
Error Handling / 错误处理
API密钥未配置:
ZHIPUAPIKEY not configured. Get your API key at: https://bigmodel.cn/usercenter/proj-mgmt/apikeys
→ 向用户显示确切错误,引导他们配置
认证失败(401/403): API密钥无效/已过期 → 重新配置
速率限制(429): 配额已用完 → 告知用户等待
文件未找到: 本地文件缺失 → 检查路径