AI Agent Guidelines for Models via API

Base URL: <https://app.nanonets.com>

Add or Update AI Agent Guidelines

Endpoint

PATCH /api/v2/ObjectDetection/Model/{model_id}

Description

This endpoint allows you to add or update AI Agent guidelines within a specified model.

Request Parameters

  • model_id (string, required): The unique identifier of the model that the file belongs to.

Body Parameters

  • field_instructions (string, required): Add any instructions for model to follow during field predictions
  • table_instructions (string, required): Add any instructions for model to follow during table predictions
  • ai_guidelines (bool, required): True

Sample Request:

curl:

curl -X POST "https://app.nanonets.com/api/v2/ObjectDetection/Model/{model_id}" \
-H "Content-Type: application/json" \
-u "API_KEY:"
--data '{
    "field_instructions": "For Vendor ABC:\n1. Always extract the vendor name as \"ABC\" (not Alpha Beta Charlie)\n2. Convert all dates to ISO format (yyyy-mm-dd)\n\nAND\n\nFor Vendor XYZ:\n1. Do not extract the PO number\n2. Be explicit about formatting or field logic. Specify units, formats, or keywords to include or exclude, such as \"only extract values in USD\".",
    "table_instructions": "For all invoices:\n1. Extract line item details including item description, quantity, unit price, and total amount\n2. For item descriptions, include the full text even if it spans multiple lines\n\nAND\n\nFor purchase orders:\n1. Extract all line items including SKU numbers\n2. Format quantities as numbers without units\n3. Ensure all monetary values are in the same currency as the document total",
    "ai_guidelines": true
}'

Python:

import requests

url = "https://app.nanonets.com/api/v2/ObjectDetection/Model/{model_id}"

api_key = 'API_KEY'

payload = {
    "field_instruction": """For Vendor ABC:
1. Always extract the vendor name as "ABC" (not Alpha Beta Charlie)
2. Convert all dates to ISO format (yyyy-mm-dd)

AND

For Vendor XYZ:
1. Do not extract the PO number
2. Be explicit about formatting or field logic. Specify units, formats, or keywords to include or exclude, such as "only extract values in USD".""",
    "table_instructions": """For all invoices:
1. Extract line item details including item description, quantity, unit price, and total amount
2. For item descriptions, include the full text even if it spans multiple lines

AND

For purchase orders:
1. Extract all line items including SKU numbers
2. Format quantities as numbers without units
3. Ensure all monetary values are in the same currency as the document total""",
    "ai_guidelines": True
}

response = requests.post(url, auth=(api_key, ''), headers={"Content-Type": "application/json"}, json=payload)

print(response.text)



Points to note:

  • The AI Agent guidelines will work only for Instant Learning Models