SuperAPI AI Directory

glmocr-table

Data & analytics

View repository

Updated 10-16 07:22

About this skill

GLM-OCR Table Recognition Skill / GLM-OCR Table Recognition Skill

Extract tables from images and PDFs and convert them to Markdown format using the ZhiPu GLM-OCR layout parsing API.

When to Use / When to Use

  • Extract tables from images or scanned documents / Extract tables from images or scanned documents
  • Convert table images to Markdown or Excel format / Convert table images to Markdown or editable format
  • Recognize complex tables with merged cells / Recognize complex tables with merged cells
  • Parse financial statements, invoices, reports with tables / Parse financial statements, invoices, reports with tables
  • User mentions "extract table", "recognize table", or Chinese equivalents such as "表格识别" (table recognition), "提取表格" (extract tables), "表格OCR" (table OCR), and "表格转文字" (convert tables to text).

Key Features / 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 / Resource Links

Resource Link
Get API Key Zhipu Open Platform API Keys
API Docs Layout Parsing / Layout Parsing

Prerequisites / Prerequisites

API Key Setup / API Key Setup (Required)

The script obtains the key via the ZHIPU_API_KEY environment variable, and can reuse the same key with other Zhipu skills. This script reads the key from the ZHIPU_API_KEY environment variable. Reusing the same key across Zhipu skills is optional.

Get Key: Visit Zhipu Open Platform API Keys to create or copy your key.

Setup options / Setup options (choose one):

  1. Global config (recommended) / Global config (recommended): Set once in openclaw.json under env.vars, all Zhipu skills will share it:

    {
      "env": {
        "vars": {
          "ZHIPU_API_KEY": "你的密钥"
        }
      }
    }
    
  2. Skill-level config / Skill-level config: Set for this skill only in openclaw.json:

    {
      "skills": {
        "entries": {
          "glmocr-table": {
            "env": {
              "ZHIPU_API_KEY": "你的密钥"
            }
          }
        }
      }
    }
    
  3. Shell environment variable / Shell environment variable: Add to ~/.zshrc:

    export ZHIPU_API_KEY="你的密钥"
    

💡 If you have already configured a key for other Zhipu skills (such as glmocr、glmv-caption、glm-image-generation) they share the same ZHIPU_API_KEY, no need to configure again.

Security & Transparency / Security & Transparency

  • Environment variables used / Environment variables used:
    • ZHIPU_API_KEY (required)
    • GLM_OCR_TIMEOUT (optional timeout seconds)
  • Fixed endpoint / Fixed official endpoint: https://open.bigmodel.cn/api/paas/v4/layout_parsing
  • No custom API URL override / No custom API URL override: this avoids accidental key exfiltration via redirected endpoints.
  • Raw upstream response is optional / Raw response is not returned by default: use --include-raw only when needed for debugging.

⛔ MANDATORY RESTRICTIONS / MANDATORY RESTRICTIONS ⛔

  1. ONLY use GLM-OCR API — Execute the script python scripts/glm_ocr_cli.py
  2. NEVER parse tables yourself — Do NOT try to extract tables using built-in vision or any other method
  3. NEVER offer alternatives — Do NOT suggest "I can try to recognize it" or similar
  4. IF API fails — Display the error message and STOP immediately
  5. NO fallback methods — Do NOT attempt table extraction any other way

📋 Output Display Rules / 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 / How to Use

Extract from URL / Extract from URL

python scripts/glm_ocr_cli.py --file-url "https://example.com/table.png"

Extract from Local File / Extract from Local File

python scripts/glm_ocr_cli.py --file /path/to/table.png

Save Result to File / Save Result to File

python scripts/glm_ocr_cli.py --file table.png --output result.json --pretty

Include Raw Upstream Response (Debug Only) / Include Raw Upstream Response (Debug Only)

python scripts/glm_ocr_cli.py --file table.png --output result.json --include-raw

CLI Reference / CLI Reference

python {baseDir}/scripts/glm_ocr_cli.py (--file-url URL | --file PATH) [--output FILE] [--pretty] [--include-raw]
Parameter Required Description
--file-url One of URL to image/PDF
--file 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 / Response Format

{
  "ok": true,
  "text": "| Column 1 | Column 2 |\n|----------|----------|\n| Data     | Data     |",
  "layout_details": [...],
  "result": null,
  "error": null,
  "source": "/path/to/file",
  "source_type": "file",
  "raw_result_included": false
}

Key fields:

  • ok — whether extraction succeeded
  • text — extracted text in Markdown (use this for display)
  • layout_details — layout analysis details
  • error — error details on failure

Error Handling / Error Handling

API key not configured:

ZHIPU_API_KEY not configured. Get your API key at: https://bigmodel.cn/usercenter/proj-mgmt/apikeys

→ 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