Create and manage document type configurations — the extraction schema, validation rules, and classification hints
Document Types
Document types (internally called contexts) define how 9thSense processes a particular class of document. Each document type specifies an extraction schema, validation rules, classification hints, and the pipeline steps to run.
The Library ships 40+ pre-built document types covering identity, financial, travel, and business documents. You can use them as-is, customise them, or create entirely new ones.
Document Type Object
context_idstringUnique snake_case identifier (e.g. "pan_card", "aadhaar").
tenant_idstringTenant that owns this type. Empty string for global (shared) types.
display_namestringHuman-readable name (e.g. "PAN Card").
input_typestring"document" or "image".
analysis_typestring"extraction", "scene_understanding", or "classification".
model_hintstring"vlm" for documents/images, "llm" for text-only processing.
categorystring"identity", "financial", "travel", "business", "scene", or "other".
output_schemaobjectField definitions: { field_name: type_hint_string }. E.g. { "name": "string", "date_of_birth": "YYYY-MM-DD or null" }.
validation_rulesobjectPer-field rules: { field_name: { required: bool, regex: "...", mask: bool, format: "..." } }.
classify_hintsstring[]Keywords and phrases that uniquely identify this document type (used by the classifier).
pipeline_stepsstring[]Ordered list of pipeline steps (e.g. ["classify", "extract", "validate"]).
prompt_hintstringExtraction guidance injected into the VLM prompt — format quirks, common gotchas.
enabledbooleanWhether this type is active.
CRUD Endpoints
Create Document Type
POST /v1/document-types
Requires scope: write. Returns 201.
Request body:
context_idstringrequiredUnique snake_case ID (e.g. "vehicle_rc").
display_namestringrequiredHuman-readable name.
tenant_idstringTenant to scope this type to. Leave empty for a global type.
output_schemaobjectrequiredField definitions mapping field names to type hint strings.
validation_rulesobjectPer-field validation rules.
classify_hintsstring[]Keywords for classification.
pipeline_stepsstring[]Ordered pipeline steps.
prompt_hintstringExtraction guidance for the VLM.
categorystringOne of: identity, financial, travel, business, scene, other.
input_typestring"document" or "image". Default "document".
analysis_typestring"extraction", "scene_understanding", or "classification". Default "extraction".
model_hintstring"vlm" or "llm". Default "vlm".
enabledbooleanWhether to enable the type immediately. Default true.
Example request:
{
"context_id": "vehicle_rc",
"display_name": "Vehicle Registration Certificate",
"tenant_id": "acme-corp",
"category": "identity",
"output_schema": {
"registration_number": "string",
"owner_name": "string",
"vehicle_class": "string",
"fuel_type": "string",
"registration_date": "YYYY-MM-DD or null"
},
"validation_rules": {
"registration_number": { "required": true, "mask": true },
"owner_name": { "required": true }
},
"classify_hints": ["vehicle registration", "RC book", "Motor Vehicles Act"],
"pipeline_steps": ["classify", "extract", "validate"]
}
Response (201): Document Type object.
List Document Types
GET /v1/document-types
Requires scope: read.
Query parameters:
tenant_idstringFilter by tenant. Returns global types when empty.
Response (200): Array of Document Type objects.
Get Document Type
GET /v1/document-types/{context_id}
Requires scope: read. Falls back to the global (empty tenant) version if no tenant-specific type is found.
context_idstringrequiredDocument type ID (e.g. "pan_card").
tenant_idstringTenant to scope the lookup.
Update Document Type
PUT /v1/document-types/{context_id}
Requires scope: write. Automatically snapshots the current state before applying the update.
context_idstringrequiredtenant_idstringRequest body: Same fields as Create (all optional on update).
Delete Document Type
DELETE /v1/document-types/{context_id}
Requires scope: write. Returns 204 No Content.
context_idstringrequiredtenant_idstringLock Fields (Progressive Schema Refinement)
PATCH /v1/document-types/{context_id}/lock-fields
Requires scope: write. Merges new fields into the existing output_schema and optionally auto-suggests validation rules for the added fields. Use this after a discover run to commit discovered fields to the schema.
context_idstringrequiredtenant_idstringRequest body:
fieldsobjectrequiredMap of { field_name: type_hint } to merge into the schema.
rulesobjectExplicit validation rules to set for specific fields.
auto_suggestbooleanIf true, auto-generates validation rules for fields that don't have explicit rules (uses field name heuristics). Default false.
List Document Type Versions
GET /v1/document-types/{context_id}/versions
Requires scope: read. Returns the version history of a document type.
context_idstringrequiredResponse (200):
idstringcontext_idstringtenant_idstringdisplay_namestringconfigobjectnotestringcreated_atstringAI-Assisted Creation
Discover from Sample Documents
POST /v1/document-types/discover
Requires scope: write. Upload 1–3 sample documents — 9thSense uses a VLM to identify the document type, extract all fields, suggest an output schema, suggest validation rules, and generate classification hints.
Request body:
documentsobject[]requiredArray of sample document objects. Each: { "data": "<base64>", "mime_type": "image/jpeg" }. Up to 3 samples — more samples improve field coverage.
Response (200):
context_idstring"pan_card").display_namestring"PAN Card").suggested_schemaobjectoutput_schema.suggested_rulesobjectvalidation_rules.classify_hintsstring[]sample_extractionobjectGenerate from Description
POST /v1/document-types/generate
Requires scope: write. Describe a document type in plain text — an LLM generates a complete configuration including schema, validation rules, classification hints, and extraction guidance.
Request body:
descriptionstringrequiredPlain-text description of the document type (e.g. "Indian driving license issued by transport department, has front and back sides, contains license number, name, DOB, address, vehicle classes").
tenant_idstringResponse (200):
context_idstringdisplay_namestringcategorystringinput_typestringanalysis_typestringmodel_hintstringsuggested_schemaobjectsuggested_rulesobjectclassify_hintsstring[]prompt_hintstring