> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/data-science/genai-models/llm-helpers.md).

# LLM Helpers

Rierino includes several Python helpers for fine-tuning and complementing GenAI models

LLM helpers provided by Rierino can be deployed as stand-alone Jobs for long running processes, serviced through Python-Java bridge to embed into saga flows, or served over our Python API runner, exposing these capabilities as following standalone API endpoints:

## Extract text from a PDF (pdfplumber + OCR fallback)

> Tries pdfplumber first; falls back to Tesseract/Paddle OCR for scanned, rotated, or low-yield PDFs. Optionally chunks the extracted markdown.<br>

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"Document Parsing","description":"Extract text/markdown and chunks from PDFs, spreadsheets, Office files, images, HTML, and audio."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.ocr/OCRProcess":{"post":{"tags":["Document Parsing"],"operationId":"ocrProcess","summary":"Extract text from a PDF (pdfplumber + OCR fallback)","description":"Tries pdfplumber first; falls back to Tesseract/Paddle OCR for scanned, rotated, or low-yield PDFs. Optionally chunks the extracted markdown.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OCRRequest"}}}},"responses":{"200":{"description":"Extracted text (and chunks when chunking is enabled).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TextExtractionResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"OCRRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","required":["source"],"properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}},"source":{"$ref":"#/components/schemas/FileSource"},"parameters":{"$ref":"#/components/schemas/OCRParameters"}}}}},"Connection":{"type":"object","description":"A named data connection referenced by `source.connection` (and by dataset inputs). Extra backend-specific keys are allowed.\n","additionalProperties":true,"required":["name"],"properties":{"name":{"type":"string","description":"Connection name referenced elsewhere in `args`."},"type":{"type":"string","description":"Backend type, e.g. `fs`, `s3`, `ftp`."},"pandasOptions":{"type":"array","items":{},"description":"Optional backend-specific options."}}},"FileSource":{"type":"object","description":"A document source. Provide exactly one of `base64Data` or `path` (with a matching `connection`).\n","properties":{"base64Data":{"type":"string","description":"Base64-encoded file content, with or without a `data:...;base64,` prefix."},"path":{"type":"string","description":"Remote file path, downloaded through the named `connection`."},"connection":{"type":"string","description":"Name of the connection to use when `path` is set."},"filename":{"type":"string","description":"Docling only — optional file-type hint for `base64Data` (defaults to `.pdf`)."},"format":{"type":"string","description":"Docling only — alternative file-type hint for `base64Data`."}}},"OCRParameters":{"type":"object","additionalProperties":true,"properties":{"ocr_engine":{"type":"string","enum":["tesseract","paddle","auto"],"default":"tesseract"},"min_chars":{"type":"integer","default":100},"min_avg_word_len":{"type":"number","default":3},"ocr_page_min_chars":{"type":"integer","default":50,"description":"auto mode only."},"dpi_retry":{"type":"integer","default":300,"description":"auto mode only (0 disables)."},"extract":{"type":"object","description":"pdfplumber open options (e.g. password).","additionalProperties":true},"ocr":{"type":"object","description":"Shared OCR options (lang, device, ...).","additionalProperties":true,"properties":{"lang":{"type":"string"},"device":{"type":"string","enum":["cpu","gpu"],"default":"cpu"}}},"ocr_tesseract":{"type":"object","additionalProperties":true},"ocr_paddle":{"type":"object","additionalProperties":true},"page":{"type":"object","additionalProperties":true,"properties":{"first_page":{"type":["integer","null"]},"last_page":{"type":["integer","null"]},"concatenate_pages":{"type":"boolean","default":true},"dpi":{"type":"integer","default":200},"extract_tables":{"type":"boolean","default":true},"char_threshold":{"type":"integer","default":10},"text_params":{"type":"object","additionalProperties":true}}},"chunk":{"$ref":"#/components/schemas/MarkdownChunkParams"}}},"MarkdownChunkParams":{"type":"object","description":"Markdown chunker options (OCR `parameters.chunk` and ChunkProcess `parameters`).","properties":{"enabled":{"type":"boolean","default":false,"description":"OCR only — master toggle."},"strategy":{"type":"string","enum":["recursive","markdown","fixed","page"],"default":"recursive"},"chunk_size":{"type":"integer","default":1000},"size_unit":{"type":"string","enum":["chars","words","tokens"],"default":"chars"},"chunk_overlap":{"type":"integer","default":150},"min_chunk_size":{"type":"integer","default":100},"respect_headers":{"type":"boolean","default":true},"header_split_level":{"type":"integer","default":2},"respect_tables":{"type":"boolean","default":true},"respect_pages":{"type":"boolean","default":false},"token_encoding":{"type":"string","default":"cl100k_base"},"include_metadata":{"type":"boolean","default":true}},"additionalProperties":true},"TextExtractionResult":{"type":"object","properties":{"md":{"type":["string","null"],"description":"Extracted text. `null` if no source; empty string if extraction yielded nothing."},"chunks":{"type":"array","description":"Present only when `chunk.enabled` is true.","items":{"$ref":"#/components/schemas/Chunk"}}}},"Chunk":{"type":"object","properties":{"text":{"type":"string"},"metadata":{"type":"object","additionalProperties":true,"properties":{"index":{"type":"integer"},"page_start":{"type":["integer","null"]},"page_end":{"type":["integer","null"]},"pages":{"type":"array","items":{"type":"integer"}},"headings":{"type":"array","items":{"type":"string"}},"heading_path":{"type":"string"},"char_count":{"type":"integer"},"token_count":{"type":["integer","null"]},"is_table":{"type":"boolean"}}}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```

## Convert an Excel workbook to Markdown tables

> Renders each sheet as a Markdown table; sheet names become level-2 headings.

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"Document Parsing","description":"Extract text/markdown and chunks from PDFs, spreadsheets, Office files, images, HTML, and audio."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.xlsx/XLSXProcess":{"post":{"tags":["Document Parsing"],"operationId":"xlsxProcess","summary":"Convert an Excel workbook to Markdown tables","description":"Renders each sheet as a Markdown table; sheet names become level-2 headings.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/XLSXRequest"}}}},"responses":{"200":{"description":"All sheets rendered as Markdown.","content":{"application/json":{"schema":{"type":"object","properties":{"md":{"type":["string","null"],"description":"All sheets as Markdown tables. `null` if no source was provided."}}}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"XLSXRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","required":["source"],"properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}},"source":{"$ref":"#/components/schemas/FileSource"},"parameters":{"type":"object","properties":{"excel":{"type":"object","description":"Forwarded to pandas.read_excel.","additionalProperties":true,"properties":{"sheet_name":{},"header":{},"skiprows":{},"usecols":{},"dtype":{"type":"object","additionalProperties":true},"na_values":{"type":"array","items":{}},"engine":{"type":"string"}}},"markdown":{"type":"object","description":"Forwarded to DataFrame.to_markdown.","additionalProperties":true,"properties":{"index":{"type":"boolean","default":false},"tablefmt":{"type":"string","default":"pipe"},"floatfmt":{"type":"string","default":"g"},"numalign":{"type":"string","default":"right"},"stralign":{"type":"string","default":"left"}}}}}}}}},"Connection":{"type":"object","description":"A named data connection referenced by `source.connection` (and by dataset inputs). Extra backend-specific keys are allowed.\n","additionalProperties":true,"required":["name"],"properties":{"name":{"type":"string","description":"Connection name referenced elsewhere in `args`."},"type":{"type":"string","description":"Backend type, e.g. `fs`, `s3`, `ftp`."},"pandasOptions":{"type":"array","items":{},"description":"Optional backend-specific options."}}},"FileSource":{"type":"object","description":"A document source. Provide exactly one of `base64Data` or `path` (with a matching `connection`).\n","properties":{"base64Data":{"type":"string","description":"Base64-encoded file content, with or without a `data:...;base64,` prefix."},"path":{"type":"string","description":"Remote file path, downloaded through the named `connection`."},"connection":{"type":"string","description":"Name of the connection to use when `path` is set."},"filename":{"type":"string","description":"Docling only — optional file-type hint for `base64Data` (defaults to `.pdf`)."},"format":{"type":"string","description":"Docling only — alternative file-type hint for `base64Data`."}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```

## Convert a document to markdown/html/json/text via docling

> Converts PDFs, Office files, images, HTML, and audio into a chosen format, with an optional layout-aware chunking step.<br>

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"Document Parsing","description":"Extract text/markdown and chunks from PDFs, spreadsheets, Office files, images, HTML, and audio."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.docling/DoclingProcess":{"post":{"tags":["Document Parsing"],"operationId":"doclingProcess","summary":"Convert a document to markdown/html/json/text via docling","description":"Converts PDFs, Office files, images, HTML, and audio into a chosen format, with an optional layout-aware chunking step.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DoclingRequest"}}}},"responses":{"200":{"description":"Converted document (and chunks when chunking is enabled).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DoclingResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"DoclingRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","required":["source"],"properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}},"source":{"$ref":"#/components/schemas/FileSource"},"parameters":{"$ref":"#/components/schemas/DoclingParameters"}}}}},"Connection":{"type":"object","description":"A named data connection referenced by `source.connection` (and by dataset inputs). Extra backend-specific keys are allowed.\n","additionalProperties":true,"required":["name"],"properties":{"name":{"type":"string","description":"Connection name referenced elsewhere in `args`."},"type":{"type":"string","description":"Backend type, e.g. `fs`, `s3`, `ftp`."},"pandasOptions":{"type":"array","items":{},"description":"Optional backend-specific options."}}},"FileSource":{"type":"object","description":"A document source. Provide exactly one of `base64Data` or `path` (with a matching `connection`).\n","properties":{"base64Data":{"type":"string","description":"Base64-encoded file content, with or without a `data:...;base64,` prefix."},"path":{"type":"string","description":"Remote file path, downloaded through the named `connection`."},"connection":{"type":"string","description":"Name of the connection to use when `path` is set."},"filename":{"type":"string","description":"Docling only — optional file-type hint for `base64Data` (defaults to `.pdf`)."},"format":{"type":"string","description":"Docling only — alternative file-type hint for `base64Data`."}}},"DoclingParameters":{"type":"object","additionalProperties":true,"properties":{"format":{"type":"string","enum":["md","html","json","text","doctags","vtt","doclang"],"default":"md"},"asr_model":{"type":"string","default":"WHISPER_TURBO"},"convert":{"type":"object","additionalProperties":true,"properties":{"page_range":{"type":"array","items":{"type":"integer"},"minItems":2,"maxItems":2},"max_num_pages":{"type":"integer"},"max_file_size":{"type":"integer"},"headers":{"type":"object","additionalProperties":true}}},"pipeline":{"type":"object","additionalProperties":true,"properties":{"do_ocr":{"type":"boolean"},"do_table_structure":{"type":"boolean"},"images_scale":{"type":"number"},"generate_page_images":{"type":"boolean"},"generate_picture_images":{"type":"boolean"},"table_structure_options":{"type":"object","additionalProperties":true},"accelerator_options":{"type":"object","additionalProperties":true}}},"vlm":{"type":"object","additionalProperties":true,"properties":{"url":{"type":"string"},"model":{"type":"string"},"headers":{"type":"object","additionalProperties":true},"prompt":{"type":"string"},"response_format":{"type":"string","enum":["markdown","doctags","html","otsl","plaintext"],"default":"markdown"},"timeout":{"type":"number","default":60},"concurrency":{"type":"integer","default":1},"scale":{"type":"number","default":2}}},"chunk":{"$ref":"#/components/schemas/DoclingChunkParams"}}},"DoclingChunkParams":{"type":"object","description":"Docling chunker options.","properties":{"enabled":{"type":"boolean","default":false,"description":"DoclingProcess only — ignored by ChunkerProcess."},"type":{"type":"string","enum":["hybrid","hierarchical"],"default":"hybrid"},"max_tokens":{"type":"integer"},"merge_peers":{"type":"boolean","default":true},"contextualize":{"type":"boolean","default":true},"include_metadata":{"type":"boolean","default":true}},"additionalProperties":true},"DoclingResult":{"type":"object","properties":{"format":{"type":"string"},"content":{"type":["string","null"],"description":"Converted document. `null` if no source or conversion failed."},"chunks":{"type":"array","description":"Present only when `chunk.enabled` is true.","items":{"$ref":"#/components/schemas/Chunk"}}}},"Chunk":{"type":"object","properties":{"text":{"type":"string"},"metadata":{"type":"object","additionalProperties":true,"properties":{"index":{"type":"integer"},"page_start":{"type":["integer","null"]},"page_end":{"type":["integer","null"]},"pages":{"type":"array","items":{"type":"integer"}},"headings":{"type":"array","items":{"type":"string"}},"heading_path":{"type":"string"},"char_count":{"type":"integer"},"token_count":{"type":["integer","null"]},"is_table":{"type":"boolean"}}}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```

## POST /api/request/rierino\_llm.docling/ChunkerProcess

> Convert and chunk a document with docling's layout-aware chunker

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"Document Parsing","description":"Extract text/markdown and chunks from PDFs, spreadsheets, Office files, images, HTML, and audio."},{"name":"Chunking","description":"Split text/markdown into retrieval-friendly chunks for RAG."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.docling/ChunkerProcess":{"post":{"tags":["Document Parsing","Chunking"],"operationId":"doclingChunkerProcess","summary":"Convert and chunk a document with docling's layout-aware chunker","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DoclingChunkerRequest"}}}},"responses":{"200":{"description":"Docling-native chunks.","content":{"application/json":{"schema":{"type":"object","properties":{"chunks":{"type":["array","null"],"items":{"$ref":"#/components/schemas/Chunk"}}}}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"DoclingChunkerRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","required":["source"],"properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}},"source":{"$ref":"#/components/schemas/FileSource"},"parameters":{"allOf":[{"$ref":"#/components/schemas/DoclingChunkParams"},{"type":"object","properties":{"asr_model":{"type":"string","default":"WHISPER_TURBO"},"convert":{"type":"object","additionalProperties":true}}}]}}}}},"Connection":{"type":"object","description":"A named data connection referenced by `source.connection` (and by dataset inputs). Extra backend-specific keys are allowed.\n","additionalProperties":true,"required":["name"],"properties":{"name":{"type":"string","description":"Connection name referenced elsewhere in `args`."},"type":{"type":"string","description":"Backend type, e.g. `fs`, `s3`, `ftp`."},"pandasOptions":{"type":"array","items":{},"description":"Optional backend-specific options."}}},"FileSource":{"type":"object","description":"A document source. Provide exactly one of `base64Data` or `path` (with a matching `connection`).\n","properties":{"base64Data":{"type":"string","description":"Base64-encoded file content, with or without a `data:...;base64,` prefix."},"path":{"type":"string","description":"Remote file path, downloaded through the named `connection`."},"connection":{"type":"string","description":"Name of the connection to use when `path` is set."},"filename":{"type":"string","description":"Docling only — optional file-type hint for `base64Data` (defaults to `.pdf`)."},"format":{"type":"string","description":"Docling only — alternative file-type hint for `base64Data`."}}},"DoclingChunkParams":{"type":"object","description":"Docling chunker options.","properties":{"enabled":{"type":"boolean","default":false,"description":"DoclingProcess only — ignored by ChunkerProcess."},"type":{"type":"string","enum":["hybrid","hierarchical"],"default":"hybrid"},"max_tokens":{"type":"integer"},"merge_peers":{"type":"boolean","default":true},"contextualize":{"type":"boolean","default":true},"include_metadata":{"type":"boolean","default":true}},"additionalProperties":true},"Chunk":{"type":"object","properties":{"text":{"type":"string"},"metadata":{"type":"object","additionalProperties":true,"properties":{"index":{"type":"integer"},"page_start":{"type":["integer","null"]},"page_end":{"type":["integer","null"]},"pages":{"type":"array","items":{"type":"integer"}},"headings":{"type":"array","items":{"type":"string"}},"heading_path":{"type":"string"},"char_count":{"type":"integer"},"token_count":{"type":["integer","null"]},"is_table":{"type":"boolean"}}}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```

## POST /api/request/rierino\_llm.chunk/ChunkProcess

> Chunk text/markdown you already have (no OCR)

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"Chunking","description":"Split text/markdown into retrieval-friendly chunks for RAG."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.chunk/ChunkProcess":{"post":{"tags":["Chunking"],"operationId":"chunkProcess","summary":"Chunk text/markdown you already have (no OCR)","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChunkRequest"}}}},"responses":{"200":{"description":"Chunks.","content":{"application/json":{"schema":{"type":"object","properties":{"chunks":{"type":["array","null"],"items":{"$ref":"#/components/schemas/Chunk"}}}}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"ChunkRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","required":["source"],"properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}},"source":{"type":"object","description":"Provide one of text/md, pages, base64Data, or path.","properties":{"text":{"type":"string"},"md":{"type":"string"},"pages":{"type":"array","description":"Pre-paginated input; strings, [page, text] pairs, or {page, text} dicts.","items":{}},"base64Data":{"type":"string"},"path":{"type":"string"},"connection":{"type":"string"},"start_page":{"type":"integer","default":1},"page_delimiter":{"type":"string"}}},"parameters":{"$ref":"#/components/schemas/MarkdownChunkParams"}}}}},"Connection":{"type":"object","description":"A named data connection referenced by `source.connection` (and by dataset inputs). Extra backend-specific keys are allowed.\n","additionalProperties":true,"required":["name"],"properties":{"name":{"type":"string","description":"Connection name referenced elsewhere in `args`."},"type":{"type":"string","description":"Backend type, e.g. `fs`, `s3`, `ftp`."},"pandasOptions":{"type":"array","items":{},"description":"Optional backend-specific options."}}},"MarkdownChunkParams":{"type":"object","description":"Markdown chunker options (OCR `parameters.chunk` and ChunkProcess `parameters`).","properties":{"enabled":{"type":"boolean","default":false,"description":"OCR only — master toggle."},"strategy":{"type":"string","enum":["recursive","markdown","fixed","page"],"default":"recursive"},"chunk_size":{"type":"integer","default":1000},"size_unit":{"type":"string","enum":["chars","words","tokens"],"default":"chars"},"chunk_overlap":{"type":"integer","default":150},"min_chunk_size":{"type":"integer","default":100},"respect_headers":{"type":"boolean","default":true},"header_split_level":{"type":"integer","default":2},"respect_tables":{"type":"boolean","default":true},"respect_pages":{"type":"boolean","default":false},"token_encoding":{"type":"string","default":"cl100k_base"},"include_metadata":{"type":"boolean","default":true}},"additionalProperties":true},"Chunk":{"type":"object","properties":{"text":{"type":"string"},"metadata":{"type":"object","additionalProperties":true,"properties":{"index":{"type":"integer"},"page_start":{"type":["integer","null"]},"page_end":{"type":["integer","null"]},"pages":{"type":"array","items":{"type":"integer"}},"headings":{"type":"array","items":{"type":"string"}},"heading_path":{"type":"string"},"char_count":{"type":"integer"},"token_count":{"type":["integer","null"]},"is_table":{"type":"boolean"}}}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```

## Detect and anonymize PII in text

> Replaces detected PII with reversible \`\<ENTITY\_hex>\` placeholders (UUID mode) or Presidio operators. Supports custom entity lists with exact and fuzzy matching.<br>

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"PII Anonymization","description":"Detect and remove PII before an LLM call, and restore it afterwards."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.anonymizer/AnonymizerProcess":{"post":{"tags":["PII Anonymization"],"operationId":"anonymizerProcess","summary":"Detect and anonymize PII in text","description":"Replaces detected PII with reversible `<ENTITY_hex>` placeholders (UUID mode) or Presidio operators. Supports custom entity lists with exact and fuzzy matching.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnonymizeRequest"}}}},"responses":{"200":{"description":"Anonymized text and reversal mapping.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnonymizeResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"AnonymizeRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}},"parameters":{"type":"object","properties":{"text":{"type":"string"},"uuid":{"type":"boolean","default":false},"analyzer":{"type":"object","additionalProperties":true,"properties":{"supported_languages":{"type":"array","items":{"type":"string"}},"default_score_threshold":{"type":"number","default":0.35},"language":{"type":"string","default":"en"},"entities":{"type":"array","items":{"type":"string"}},"score_threshold":{"type":"number"},"allow_list":{"type":"array","items":{"type":"string"}},"context":{"type":"array","items":{"type":"string"}},"log_decision_process":{"type":"boolean","default":false}}},"anonymizer":{"type":"object","description":"Operator config; used only when uuid is false.","properties":{"operators":{"type":"object","additionalProperties":{"$ref":"#/components/schemas/Operator"}}}}}},"lists":{"type":"array","items":{"$ref":"#/components/schemas/CustomList"}}}}}},"Connection":{"type":"object","description":"A named data connection referenced by `source.connection` (and by dataset inputs). Extra backend-specific keys are allowed.\n","additionalProperties":true,"required":["name"],"properties":{"name":{"type":"string","description":"Connection name referenced elsewhere in `args`."},"type":{"type":"string","description":"Backend type, e.g. `fs`, `s3`, `ftp`."},"pandasOptions":{"type":"array","items":{},"description":"Optional backend-specific options."}}},"Operator":{"type":"object","additionalProperties":true,"properties":{"type":{"type":"string","enum":["replace","redact","mask","hash","encrypt"]},"new_value":{"type":"string"},"masking_char":{"type":"string"},"chars_to_mask":{"type":"integer"},"from_end":{"type":"boolean"},"hash_type":{"type":"string","enum":["sha256","sha512","md5"]},"key":{"type":"string"}}},"CustomList":{"type":"object","additionalProperties":true,"properties":{"entity":{"type":"string","default":"CUSTOM_ORG"},"name":{"type":"string","default":"custom_dict"},"language":{"type":"string","default":"en"},"context":{"type":"array","items":{"type":"string"}},"pattern":{"type":"boolean","default":false},"fuzzy":{"type":"boolean","default":false},"pattern_score":{"type":"number","default":0.85},"fuzzy_threshold":{"type":"number","default":0.9},"fuzzy_min_alpha_chars":{"type":"integer","default":6},"fuzzy_prefix_only":{"type":"boolean","default":false},"records":{"type":"array","description":"Strings or {id, label} objects.","items":{}},"path":{"type":"string","description":"CSV file with a `label` column."}}},"AnonymizeResult":{"type":"object","properties":{"result":{"type":["string","null"]},"mapping":{"type":["object","null"],"additionalProperties":{"$ref":"#/components/schemas/MappingEntry"}}}},"MappingEntry":{"type":"object","properties":{"text":{"type":"string","description":"Original span that was replaced."},"label":{"type":"string","description":"Canonical label (custom-list matches only)."},"id":{"type":"string","description":"Record id (when present)."}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```

## POST /api/request/rierino\_llm.anonymizer/DeanonymizerProcess

> Restore PII into a string or JSON body using a mapping

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"PII Anonymization","description":"Detect and remove PII before an LLM call, and restore it afterwards."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.anonymizer/DeanonymizerProcess":{"post":{"tags":["PII Anonymization"],"operationId":"deanonymizerProcess","summary":"Restore PII into a string or JSON body using a mapping","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeanonymizeRequest"}}}},"responses":{"200":{"description":"Deanonymized result (string or body, plus per-field records in body mode).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DeanonymizeResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"DeanonymizeRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","properties":{"parameters":{"type":"object","properties":{"mapping":{"type":"object","additionalProperties":{"$ref":"#/components/schemas/MappingEntry"}},"text":{"type":"string","description":"Mutually exclusive with body."},"body":{"description":"JSON structure; all string values are traversed. Mutually exclusive with text.","oneOf":[{"type":"object","additionalProperties":true},{"type":"array","items":{}}]},"inject_label":{"type":"boolean","default":false}}}}}}},"MappingEntry":{"type":"object","properties":{"text":{"type":"string","description":"Original span that was replaced."},"label":{"type":"string","description":"Canonical label (custom-list matches only)."},"id":{"type":"string","description":"Record id (when present)."}}},"DeanonymizeResult":{"type":"object","properties":{"result":{"description":"Deanonymized string (text mode) or structure (body mode)."},"records":{"type":"object","description":"Body mode only — one entry per field that contained a custom-list placeholder.","additionalProperties":{"$ref":"#/components/schemas/MappingEntry"}}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```

## Run a multi-step LLM post-training pipeline

> Executes an ordered list of training steps (CPT, SFT, DPO, KTO, PPO, GRPO, Reward). Each step's base model defaults to the previous step's output.<br>

```json
{"openapi":"3.1.0","info":{"title":"Rierino GenAI Model Services API","version":"1.0.0"},"tags":[{"name":"LLM Fine-tuning & Training","description":"Multi-step LLM post-training (CPT, SFT, DPO, KTO, PPO, GRPO, Reward)."}],"servers":[{"url":"https://{host}","description":"Rierino runner endpoint","variables":{"host":{"default":"your-rierino-host","description":"Host (and optional port) of the Rierino runner exposing the request API."}}}],"paths":{"/api/request/rierino_llm.tuner/TuneProcess":{"post":{"tags":["LLM Fine-tuning & Training"],"operationId":"tuneProcess","summary":"Run a multi-step LLM post-training pipeline","description":"Executes an ordered list of training steps (CPT, SFT, DPO, KTO, PPO, GRPO, Reward). Each step's base model defaults to the previous step's output.\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TuneRequest"}}}},"responses":{"200":{"description":"Per-step training results.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TuneResult"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"TuneRequest":{"type":"object","required":["args"],"properties":{"args":{"type":"object","required":["model"],"properties":{"connections":{"type":"array","items":{"$ref":"#/components/schemas/Connection"}},"modelFS":{"type":"string","description":"Optional prefix for the remote step path."},"workPath":{"type":"string","description":"Local working directory for step artifacts."},"logPath":{"type":"string","description":"Optional TensorBoard logging directory."},"model":{"$ref":"#/components/schemas/TuneModel"}}}}},"Connection":{"type":"object","description":"A named data connection referenced by `source.connection` (and by dataset inputs). Extra backend-specific keys are allowed.\n","additionalProperties":true,"required":["name"],"properties":{"name":{"type":"string","description":"Connection name referenced elsewhere in `args`."},"type":{"type":"string","description":"Backend type, e.g. `fs`, `s3`, `ftp`."},"pandasOptions":{"type":"array","items":{},"description":"Optional backend-specific options."}}},"TuneModel":{"type":"object","required":["id","data"],"properties":{"id":{"type":"string"},"data":{"type":"object","required":["steps"],"properties":{"name":{"type":"string"},"version":{"type":"string"},"status":{"type":"string","description":"\"A\" to run; anything else is skipped."},"root":{"type":"string"},"directory":{"type":"string"},"steps":{"type":"array","items":{"$ref":"#/components/schemas/TuneStep"}}}}}},"TuneStep":{"type":"object","required":["id","parameters"],"properties":{"id":{"type":"string"},"identifier":{"type":"string"},"root":{"type":"string"},"parameters":{"type":"object","properties":{"training":{"$ref":"#/components/schemas/TrainingParams"},"optimization":{"$ref":"#/components/schemas/OptimizationParams"}}}}},"TrainingParams":{"type":"object","additionalProperties":true,"properties":{"method":{"type":"string","enum":["cpt","sft","dpo","kto","ppo","grpo","reward"],"default":"sft"},"class":{"type":"string"},"package":{"type":"string","default":"rierino_llm.tuner"},"model":{"type":"string"},"modelParams":{"type":"object","additionalProperties":true},"tokenizerParams":{"type":"object","additionalProperties":true},"inputs":{"$ref":"#/components/schemas/DatasetInputs"},"dataset":{"$ref":"#/components/schemas/DatasetParams"},"batchSize":{"type":"integer","default":1},"epochs":{"type":"integer","default":1},"learningRate":{"type":"number"},"gradAccum":{"type":"integer","default":1},"maxSteps":{"type":"integer"},"validationRatio":{"type":"number","default":0},"methodParams":{"type":"object","additionalProperties":true},"peft":{"type":"object","additionalProperties":true},"refModel":{"type":"string"},"rewardModel":{"type":"string"},"rewardFuncs":{"type":"array","items":{"type":"string"}},"checkpoint":{"type":"boolean","default":false},"acceptance":{"type":"object","additionalProperties":{"type":"object","properties":{"min":{"type":"number"},"max":{"type":"number"}}}},"samples":{"type":"array","items":{"type":"string"}},"args":{"type":"object","additionalProperties":true}}},"DatasetInputs":{"type":"object","properties":{"hub_id":{"type":"string"},"records":{"type":"array","items":{"type":"object","additionalProperties":true}},"base64Data":{"type":"string"},"path":{"type":"string","description":"Path","comma-separated shards":null,"or local glob.":null},"connection":{"type":"string"}}},"DatasetParams":{"type":"object","properties":{"format":{"type":"string","enum":["jsonl","json","csv","parquet","hub"]},"split":{"type":"string","default":"train"},"eval_path":{"type":"string"},"eval_split":{"type":"string"},"column_mapping":{"type":"object","additionalProperties":{"type":"string"},"description":"{ expectedColumn: sourceColumnInFile }."},"load_kwargs":{"type":"object","additionalProperties":true}}},"OptimizationParams":{"type":"object","properties":{"merge":{"type":"boolean","description":"Defaults to true when peft is set."},"push":{"type":"boolean","default":false},"hubModelId":{"type":"string"}}},"TuneResult":{"type":"object","properties":{"model":{"type":"string"},"steps":{"type":"array","items":{"type":"object","properties":{"step":{"type":"string"},"accepted":{"type":"boolean"},"output_dir":{"type":"string"},"remote_path":{"type":"string"},"hub_model_id":{"type":["string","null"]},"metrics":{"type":"object","additionalProperties":true}}}}}}},"responses":{"BadRequest":{"description":"Malformed request (bad `args`, unsupported format, or unresolvable source).","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.rierino.com/data-science/genai-models/llm-helpers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
