Skip to main content

Document Moderation

The Nanonets Python 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 Python version required: 3.7

Install the Nanonets Python SDK using pip:

pip install nanonets

Field Management

Update Field Value

Updates a specific field value in a document page.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

updated_field = client.moderation.update_field_value(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
field_data_id="field_data_123",
value="INV-2024-003"
)

Add Field Value

Adds a new field value to a document page.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

new_field = client.moderation.add_field_value(
workflow_id="workflow_123",
document_id="document_123",
page_id="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

Removes a field value from a document page.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

client.moderation.delete_field_value(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
field_data_id="field_data_123"
)

Table Management

Add Table

Adds a new table to a document page.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

table = client.moderation.add_table(
workflow_id="workflow_123",
document_id="document_123",
page_id="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.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

updated_cell = client.moderation.update_table_cell(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
table_id="table_123",
cell_id="cell_123",
value="Product B"
)

Add Table Cell

Adds a new cell to a table.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

new_cell = client.moderation.add_table_cell(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
table_id="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

Removes a cell from a table.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

client.moderation.delete_table_cell(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
table_id="table_123",
cell_id="cell_123"
)

Verification

Verify Field

Marks a field as verified.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

verified_field = client.moderation.verify_field(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
field_data_id="field_data_123",
verification_status="verified",
verification_message="Field value is correct"
)

Verify Table Cell

Marks a table cell as verified.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

verified_cell = client.moderation.verify_table_cell(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
table_id="table_123",
cell_id="cell_123",
verification_status="verified",
verification_message="Cell value is correct"
)

Verify Table

Marks an entire table as verified.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

verified_table = client.moderation.verify_table(
workflow_id="workflow_123",
document_id="document_123",
page_id="page_123",
table_id="table_123",
verification_status="verified",
verification_message="All table values are correct"
)

Verify Document

Marks an entire document as verified.

from nanonetsclient import NanonetsClient

client = NanonetsClient(api_key='your_api_key')

verified_doc = client.moderation.verify_document(
workflow_id="workflow_123",
document_id="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
from nanonets.exceptions import NanonetsError, AuthenticationError, ValidationError
from nanonetsclient import NanonetsClient

try:
client = NanonetsClient(api_key='your_api_key')
result = client.moderation.update_field_value(...)
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except ValidationError as e:
print(f"Invalid input: {e}")
except NanonetsError as e:
print(f"An error occurred: {e}")

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: