Debugging Intuitive AI Scripts¶
Custom Condition, Custom Document Condition, Custom Action and Custom Document Action scripts run on the server in a V8 engine. There is no console and no step log for your output. This page shows how to see what a script did, then lists each symptom with its cause and fix, and ends with a way to test the logic on your own machine.
At a glance
- Main tool The class Test button and its Detailed Test Results
- To see a value Throw a temporary
Error("DEBUG ..."), or pass values throughstate.UserCacheto a debug field - To check the text Show OCR Data on the subclass
- No console There is no
console, so nothing a script prints is kept
Summary¶
| Symptom | Group |
|---|---|
| Script interrupted by host | Script errors |
console is not defined |
Script errors |
fetch is not defined |
Script errors |
GlobalVariables is not defined |
Script errors |
| Illegal return statement | Script errors |
| Identifier has already been declared | Script errors |
| Cannot read properties of null | Script errors |
| Error while matching regex | Script errors |
| The wrong subclass wins | Wrong results |
| The rule's actions never run | Wrong results |
| The action wrote nothing, or the field shows another value | Wrong results |
A boolean field reads True instead of true |
Wrong results |
Tools¶
The class Test¶
- Open the class in the Intuitive AI app and select Test in the ribbon.
- In Configure Test, upload the problem documents (or select Use Training Set) and select Start Test.
- For each document, read Matched Class, Matched Subclass and Document Confidence.
- Open Detailed Test Results: Conditions and Condition Confidence show what each refiner and rule condition returned; Actions and Action Confidence show each action's result; Extraction Results show the field values that would be written; Error In Classification or Error In Extraction shows a script error.
Throw an error on purpose¶
A thrown error shows its message in the test results, with the condition id, the page and the subclass. Remove the throw before you save the class for production: an uncaught error ends the run for the document.
(function () {
var text = String(services.OcrService.GetPageOcr(state).Text || "");
throw new Error("DEBUG first 200 chars: " + text.substring(0, 200));
})();
Pass values to a debug field¶
A condition cannot write metadata, but it can put values in state.UserCache. A Custom Action in the same rule, on the same page, can read them and write a temporary Index field. Debug Notes must be an Index field; remove it when you are done.
(function () {
var text = String(services.OcrService.GetPageOcr(state).Text || "");
var score = /\binvoice\b/i.test(text) ? 0.8 : 0;
state.UserCache.Set("debugScore", String(score));
result.SetResult(score);
})();
(function () {
var score = state.UserCache.Get("debugScore");
result.SetDocumentMetadata("Debug Notes", "condition score " + (score === null ? "none" : score));
})();
Script errors¶
Script interrupted by host¶
- Message
Script execution interrupted by host - Cause The script hit its timeout: 15 minutes for page and document conditions and document actions, 5 minutes for page actions.
- Fix Ask
GetDocumentOcrfor fewer pages. Remove nested loops over OCR children. Move heavy page-action work to a document action. - See Custom Actions
console is not defined¶
- Message
ReferenceError: console is not defined - Cause The Intuitive AI engine has no
console. - Fix Remove the call. Use a thrown
Error("DEBUG ...")or a debug field, as above. - See Intuitive AI Script Reference
fetch is not defined¶
- Message
ReferenceError: fetch is not defined(orrequire,XMLHttpRequest) - Cause The engine has no network and no modules.
- Fix Move the call outside Intuitive AI: a Custom Step, a Call External API step, or your own endpoint later in the workflow.
- See Your Own Endpoint
GlobalVariables is not defined¶
- Message
ReferenceError: GlobalVariables is not defined(orbatch,builder) - Cause Those objects belong to the Custom Step, not to Intuitive AI scripts.
- Fix Read the work item snapshot from
state.BatchProjection. Write Index values withresult.SetDocumentMetadata. - See Intuitive AI Script Reference
Illegal return statement¶
- Message
SyntaxError: Illegal return statement - Cause A
returnat the top level of the script. - Fix Wrap the script in
(function () { ... })();. - See Custom Refiners
Identifier has already been declared¶
- Message
SyntaxError: Identifier 'x' has already been declared - Cause One engine runs many scripts in a run. A top-level
letorconstcollides with a name from another script. - Fix Wrap the script in a function.
- See Custom Refiners
Cannot read properties of null¶
- Message
TypeError: Cannot read properties of null (reading 'Name') - Cause
state.KnownSubclassorstate.KnownPageis null in a class-level refiner. - Fix Check for null first:
var name = state.KnownSubclass ? String(state.KnownSubclass.Name) : "";. - See Intuitive AI Script Reference
Error while matching regex¶
- Message
Error while matching regex - Cause A Regex Anchor or OCR action pattern is invalid, or it passed its 5 second timeout.
- Fix Test the pattern against the text from Show OCR Data. Avoid nested quantifiers such as
(\w+\s*)+. - See Regex Anchor Refiner
Wrong results¶
The wrong subclass wins¶
- Cause Two subclasses both return 1; or a refiner never calls
SetResultwhen its signal is missing, which means "no opinion" in a page refiner, not "no"; or another refiner on the page returns a low value (page refiners combine with And, so the lowest decides). - Fix Grade the result and add a distinguishing signal. Call
SetResult(0)when the evidence is missing. Read every refiner's Condition Confidence, not only yours. - See Pick a Vendor Subclass from Page Text
The rule's actions never run¶
- Cause The combined condition confidence is below 0.5. A Custom Document Condition result is multiplied by 0.9, so a script that returns 0.5 counts as 0.45.
- Fix Return 0.56 or more from a document condition for a match. Check each condition's value in Detailed Test Results.
- See How Classes, Refiners and Actions Fit
The action wrote nothing, or the field shows another value¶
- Cause The key does not match the Index field name exactly; or another action wrote the same field with a higher confidence; or the action reads
state.OcrCachebut the OCR action is listed after it, or in another rule; or the page rule passed on several pages and the engine kept another page's results. - Fix Copy the field name from the content type. Return
SetResult(1)for a value you trust. Put the Custom Action after the OCR action in the same rule. - See Clean a Zone Value and Write It to a Field
A boolean field reads True instead of true¶
- Cause
SetDocumentMetadataformats a JavaScript boolean on the server with .NET rules. - Fix Pass a string:
"true"or"false". Format numbers yourself too:value.toFixed(2). - See Custom Actions
Confidence outside 0 to 1
A confidence outside 0 to 1 is not an error. The engine clamps it and logs a warning.
Test the logic on your machine first¶
The scoring logic is plain JavaScript. Copy the page text from Show OCR Data and run your script under Node.js with stand-in objects. This harness runs only on your machine, not in the engine.
// Run with: node local-harness.js
var SAMPLE_TEXT = "HARBOR POINT SUPPLY\nRemit payment to: Harbor Point Supply\nVendor HPS-10422\nInvoice Total 1,234.50";
var outcome = "no opinion";
var state = { KnownSubclass: { Name: "Harbor Point Supply" } };
var services = {
OcrService: {
GetPageOcr: function () { return { Text: SAMPLE_TEXT, Confidence: 0.92 }; }
}
};
var result = {
SetResult: function (c) { outcome = c; },
SetDocumentMetadata: function (k, v) { process.stdout.write("write " + k + " = " + v + "\n"); }
};
// ---- Paste your refiner or action script here ----
(function () {
var text = String(services.OcrService.GetPageOcr(state).Text || "").replace(/\s+/g, " ");
result.SetResult(/\bharbor\s+point\s+supply\b/i.test(text) ? 0.9 : 0);
})();
// ---------------------------------------------------
process.stdout.write("confidence: " + outcome + "\n");
The harness does not reproduce .NET collections, Guids or OCR children. Test anything that uses Length(), Get() or .ToString() on host values in the class Test as well.