Thai Document OCR and Data Structuring with Typhoon and Llama 3.1 to Google Sheets - n8n Workflow

Use this powerful n8n workflow to automate extraction of complex Thai documents using Typhoon OCR and Llama 3.1, structuring the data and saving it directly via an n8n node to Google Sheets. Find more sophisticated n8n templates here.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data entry specialists dealing with high volumes of Thai government or official documents.
Organizations needing to digitize and structure large archives of non-English language paperwork.
Developers looking for advanced n8n templates integrating command-line tools (OCR) with specialized large language models (LLMs).
Users of self-hosted n8n requiring robust, multi-step data processing pipelines.

Overview

Processing documents in complex languages like Thai often requires specialized optical character recognition (OCR) and high-quality large language models (LLMs) to accurately extract and structure the data. This robust n8n workflow provides a comprehensive, automated solution.

It solves the challenge of turning unstructured PDF text into clean, structured data ready for analysis. By leveraging the power of Typhoon OCR for precise Thai text extraction and connecting it with a specialized Llama 3.1 model (via the OpenRouter n8n node) for JSON formatting, this n8n template drastically reduces manual data entry time. The final step ensures all data is cleanly organized in a Google Sheet using the dedicated Google Sheets n8n node, making this an essential tool for automated data pipeline management within the n8n environment.

How it Works

This n8n workflow operates sequentially, transforming local PDF files into spreadsheet rows:


  1. Trigger: The process begins with the 'When clicking ‘Test workflow’' n8n trigger (a manual start, though this could easily be swapped for a Watch Folder n8n node in a production environment).

  2. File Loading: The workflow uses the Read/Write File n8n node to locate and load PDF documents found within the local doc/ folder.

  3. OCR Execution: For each document, the ‘Extract Text with Typhoon OCR’ n8n node executes a Python command. This command utilizes the typhoonocr library to perform high-accuracy Thai OCR, outputting the raw text to standard output.

  4. LLM Structuring: The raw OCR output is fed into the 'Structure Text to JSON with LLM' n8n node. This specialized n8n node uses a detailed Thai prompt, specifying 10 target fields (e.g., bookid, subject, detail), instructing the LLM to format the entire text into a predictable JSON structure.

  5. LLM Backend: The language model used is the scb10x/llama3.1-typhoon2-70b-instruct model, accessed securely via the 'OpenRouter Chat Model' n8n node.

  6. Data Cleaning: The 'Parse JSON to Sheet Format' Code n8n node cleans the LLM's JSON output (removing markdown wrappers like ```json), validates the JSON structure, and flattens any complex objects (like nested contact details) into distinct columns.

  7. Final Storage: Finally, the 'Save to Google Sheet' n8n node appends the fully structured and cleaned data as a new row in the designated Google Sheets document. This completes the sophisticated n8n workflow.

Installation Guide

To utilize this document processing n8n template, follow these steps:


  1. Import: Import the provided JSON data into your self-hosted n8n instance.

  2. Environment Setup (Crucial): Since this n8n workflow relies on the executeCommand n8n node for OCR, you must ensure your n8n host machine has Python and the typhoon-ocr library installed and accessible. This specific integration requires a self-hosted setup.

  3. Typhoon API Key: In the ‘Extract Text with Typhoon OCR’ n8n node, replace in the Python command with your actual Typhoon OCR API key.

  4. Credentials:

OpenRouter: Set up credentials for the OpenRouter Chat Model n8n node to access the Llama 3.1 model.
Google Sheets: Set up OAuth2 credentials for the Google Sheets n8n node. Ensure the connected account has write access to the target spreadsheet.

  1. Google Sheet Configuration: Update the Document ID and Sheet Name in the ‘Save to Google Sheet’ n8n node to match your desired destination spreadsheet (named 'TyphoonOCRExtractedData' in the example).

  2. Testing: Place your target PDF files in a local folder named doc/ relative to your n8n execution environment before activating and running the n8n workflow.

Node Details

When clicking ‘Test workflow’ (Manual Trigger): The standard starting point for testing this n8n workflow. This n8n trigger manually initiates the data pipeline.
Load PDFs from doc Folder (Read/Write File n8n node): Scans the local doc/ directory to retrieve all files. Outputs a list of file objects, each containing the file name and path.
Extract Text with Typhoon OCR (Execute Command n8n node): Executes a custom Python script using the file path input (doc/{{$json["fileName"]}}). This powerful n8n node runs the OCR process outside of standard n8n nodes, leveraging specialized tools for Thai text recognition. Requires a locally installed Python environment.
Structure Text to JSON with LLM (Chain LLM n8n node): Directs the raw OCR text to the LLM backend (OpenRouter) with a specific, instruction-based prompt written in Thai, forcing the model to output a standardized JSON structure with 10 defined fields.
OpenRouter Chat Model (LLM n8n node): Acts as the execution engine for the Chain LLM, using the high-performance scb10x/llama3.1-typhoon2-70b-instruct model, which is optimized for complex Asian languages.
Parse JSON to Sheet Format (Code n8n node): Performs essential data manipulation. It cleans LLM artifacts, uses JSON.parse() to transform the structured text into a JavaScript object, and flattens nested contact details into separate spreadsheet columns, preparing the data perfectly for the next n8n node.


  • Save to Google Sheet (Google Sheets n8n node): Appends the fully processed and structured data to the designated sheet. Key configuration includes the use of append operation and defining 12 column mappings based on the cleaned JSON output.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

Project Manager who passionate about Automation & AI and continuously explore innovative ways to improve business processes through intelligent workflow automation. Let’s connect and automate the future!

Featured*