Answer questions about extracted data
Use Vision.Decide to answer yes/no, multiple-choice, and ordered-scale questions about JSON data your application already has. For example, evaluate an extracted invoice against an approval policy or choose its expense category.
The decision model runs locally and returns an answer and calibrated probabilities for each question. It doesn’t open or parse a document. Calibration adjusts model scores into probabilities; it doesn’t guarantee that an answer is correct. Review consequential decisions before acting on them.
Download samplePrerequisites
- .NET 10 or later and Nutrient.SDK 1.0.1 or later.
- A license covering the decision model feature, or an applicable trial.
- Internet access on first use to download model resources, a writable resource cache, and enough memory to load the model. Prepare the cache before offline use.
No API key, external model server, or input document is required for this example.
Prepare the state
Import the SDK namespace and build the shared state as a JSON string. Every question receives the same state. This example supplies an invoice and an approval limit rather than asking the model to infer a policy:
using Nutrient;
string stateJson = """ { "invoice": { "vendor": "Acme Consulting LLC", "total": 1204.50, "currency": "USD", "description": "Software and subscriptions renewal" }, "approvalLimit": 1500.00 } """;State can be a JSON object, array, or string value. For numeric rules that your application can compute exactly, prefer ordinary C# comparisons. This example illustrates the decision API’s input format; it isn’t a replacement for arithmetic validation.
Define the questions
Each question needs a unique id, a type, and nonempty instructions. The API uses these type names:
| Type | Purpose | Options |
|---|---|---|
noul | Yes/no judgment | Omit for true/false wording, or supply exactly two options in true/false order. |
choice | Choose a category | Two to 26 options, each with a nonempty key and an optional description. |
score | Choose a position on an ordered scale | Two to 26 options ordered from low to high, each with a description. Keys are optional and aren’t shown to the model. |
This example asks one question of each type:
string questionsJson = """ [ { "id": "exceeds_limit", "type": "noul", "instructions": "Does the invoice total exceed the approvalLimit in the state?", "options": [ { "key": "true", "description": "The total exceeds the approval limit." }, { "key": "false", "description": "The total does not exceed the approval limit." } ] }, { "id": "category", "type": "choice", "instructions": "Which expense category best matches the invoice description?", "options": [ { "key": "travel", "description": "Travel and lodging" }, { "key": "software", "description": "Software and subscriptions" }, { "key": "office", "description": "Office supplies and equipment" } ] }, { "id": "description_detail", "type": "score", "instructions": "How detailed is the invoice description? Use the scale from least to most detailed.", "options": [ { "description": "Vague: does not identify the goods or services." }, { "description": "General: identifies the kind of goods or services." }, { "description": "Detailed: identifies specific products, quantities, or service dates." } ] } ] """;Questions are evaluated independently. An answer to one question isn’t added to the state for the next question.
Get the decisions
Call the static Vision.Decide method and save its JSON response. There is no Document.Open or Vision.Set call:
try{ string resultJson = Vision.Decide(stateJson, questionsJson); File.WriteAllText("output.json", resultJson); Console.WriteLine("Decisions written to output.json");}catch (NutrientException e){ Console.Error.WriteLine($"Decision failed: {e.Message}"); Environment.Exit(1);}catch (IOException e){ Console.Error.WriteLine($"Could not write output.json: {e.Message}"); Environment.Exit(1);}The SDK reads option scores from the model rather than generating a free-form response. Don’t expect an explanation or a text completion in the result.
Read the output
The response has two top-level objects:
answerscontains one entry per question ID, such asanswers.category.usagecontainspromptTokensandoutputTokens. The latter counts one output token per answered question, not generated prose.
Each answer contains:
| Field | Meaning |
|---|---|
type | The question type. |
chosenIndex | Zero-based index of the selected option. |
chosenKey | The selected option’s key when supplied. This sample supplies "true"/"false" keys for yes/no and category keys for choice. Keyless score options return null in 1.0.1; add keys to those options, or use chosenIndex instead. |
confidence | Calibrated probability of the selected option. |
probabilities | Probabilities for all options in their original order. |
When noul options are omitted, 1.0.1 reports the model’s option letter, "A" or "B", as chosenKey rather than "true" or "false". Interpret chosenIndex zero as true and one as false.
For description_detail, interpret chosenIndex as a position on your three-option scale. It isn’t a continuous numeric score. Use the probability distribution to identify uncertain decisions and route them for review.
Images and request limits
To include an image in the state, embed an object with "type": "image" and a source containing an image data URI: data:<mime>;base64,<bytes>. The SDK finds these objects throughout the state and passes their image bytes to the model. Invalid embedded images fail validation.
In 1.0.1, the decision model uses a 32K-token context window. Keep the rendered state and question within the limit; oversized requests fail rather than being silently truncated. The limit applies to model tokens, not the JSON string’s character count.
Handle failures
Catch NutrientException for SDK failures, including malformed questions, invalid images, requests exceeding the context window, unavailable model resources, or a missing license entitlement. Empty or whitespace-only instructions are rejected before loading the model.
The SDK also fails when decision-model calibration is unavailable instead of returning uncalibrated probabilities. Don’t treat these failures as a negative answer to the question.
For selecting a document category from an opened file, refer to the document classification guide. For finding document boundaries in a merged PDF, refer to the document splitting guide.