Document Moderation
The Nanonets Node.js SDK provides comprehensive functionality for moderating document processing results. This guide covers all available methods for document moderation, fully aligned with the Nanonets API.
Setup
Minimum Node.js version required: 14.0.0
Install the Nanonets Node.js SDK using npm:
npm install nanonets
Field Management
Update Field Value
Updates a specific field value in a document page.
const result = await client.moderation.updateField("workflow_123", "document_123", "page_123", {
field_data_id: "field_data_123",
value: "INV-2024-003"
});
Add Field Value
Adds a new field value to a document page.
const result = await client.moderation.addField("workflow_123", "document_123", "page_123", {
field_name: "invoice_number",
value: "INV-2024-004",
bbox: [100, 200, 300, 250],
confidence: 1.0,
verification_status: "unverified",
verification_message: ""
});
Delete Field Value
Deletes a specific field value from a document page.
await client.moderation.deleteField("workflow_123", "document_123", "page_123", "field_data_123");
Table Management
Add Table
Adds a new table to a document page.
const table = await client.moderation.addTable("workflow_123", "document_123", "page_123", {
bbox: [100, 300, 800, 600],
headers: ["item_description", "quantity", "price"],
verification_status: "unverified",
verification_message: "",
cells: [
{
row: 0,
col: 0,
header: "item_description",
text: "Product A",
bbox: [100, 330, 300, 360],
verification_status: "unverified",
verification_message: ""
},
// ... more cells ...
]
});
Update Table Cell
Updates a specific cell in a table.
const updatedCell = await client.moderation.updateTableCell("workflow_123", "document_123", "page_123", "table_123", "cell_123", {
value: "Product B"
});
Add Table Cell
Adds a new cell to a table.
const newCell = await client.moderation.addTableCell("workflow_123", "document_123", "page_123", "table_123", {
row: 0,
col: 0,
header: "item_description",
text: "Product A",
bbox: [100, 330, 300, 360],
verification_status: "unverified",
verification_message: ""
});
Delete Table Cell
Deletes a specific cell from a table.
await client.moderation.deleteTableCell("workflow_123", "document_123", "page_123", "table_123", "cell_123");
Verification
Verify Field
Marks a field as verified.
const verifiedField = await client.moderation.verifyField("workflow_123", "document_123", "page_123", "field_data_123", {
verification_status: "verified",
verification_message: "Field value is correct"
});
Verify Table Cell
Marks a table cell as verified.
const verifiedCell = await client.moderation.verifyTableCell("workflow_123", "document_123", "page_123", "table_123", "cell_123", {
verification_status: "verified",
verification_message: "Cell value is correct"
});
Verify Table
Marks an entire table as verified.
const verifiedTable = await client.moderation.verifyTable("workflow_123", "document_123", "page_123", "table_123", {
verification_status: "verified",
verification_message: "All table values are correct"
});
Verify Document
Marks an entire document as verified.
const verifiedDoc = await client.moderation.verifyDocument("workflow_123", "document_123", {
verification_status: "verified",
verification_message: "All values are correct"
});
Error Handling & Common Scenarios
API error codes:
- 200 OK: Request successful
- 400 Bad Request: Invalid request parameters
- 401 Unauthorized: Invalid/missing API key
- 404 Not Found: Workflow, document, field, or table cell not found
- 409 Conflict: Invalid verification status
- 500 Internal Server Error: Server-side error
Common error scenarios:
- Invalid field/table/cell IDs
- Invalid verification status
- Missing required parameters
- Unauthorized access
const { NanonetsError, AuthenticationError, ValidationError } = require('nanonets');
try {
const result = await client.moderation.updateField(...);
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Authentication failed:", error.message);
} else if (error instanceof ValidationError) {
console.error("Invalid input:", error.message);
} else if (error instanceof NanonetsError) {
console.error("An error occurred:", error.message);
}
}
Moderation Audit Trail & Best Practices
- All moderation actions are tracked for audit purposes.
- Always verify fields and cells before marking a document as verified.
- Use clear verification messages for traceability.
- Review moderation history regularly for quality control.
For more detailed information, see: