Two invoice shapes, one C# caller
The Data Model Is an Intent File, Part 2 of 5
Acme wants the invoice number, currency, and total. Globex wants those fields plus a purchase order number. The calling code does not need an AcmeInvoice or a GlobexInvoice to capture that difference. Here are two complete intent files and a C# example that runs both without a model account.
Give each customer a contract
Place these files in an intents folder next to the console project. Acme requires three fields and keeps its invoice identifier as text:
name: Acme.Invoice.Extract
version: 1
intent: >
Extract the invoice number, total, and currency from the invoice email.
Keep the invoice number as written, including leading zeros.
Return the three-letter currency code, not a currency symbol.
shape:
kind: schema
schema:
type: object
properties:
invoiceNumber: { type: string, minLength: 1 }
currency: { type: string, enum: [USD, EUR, GBP] }
total: { type: number, minimum: 0 }
required: [invoiceNumber, currency, total]
additionalProperties: false
attempts: 2
timeout: PT15SGlobex adds a purchase order number. It requires the field to appear, but allows null when the invoice does not supply a value:
name: Globex.Invoice.Extract
version: 1
intent: >
Extract the invoice number, total, currency, and purchase order number.
Keep identifiers as written, including leading zeros.
Return the three-letter currency code. If no purchase order number
is present, return null for purchaseOrderNumber. Do not invent one.
shape:
kind: schema
schema:
type: object
properties:
invoiceNumber: { type: string, minLength: 1 }
currency: { type: string, enum: [USD, EUR, GBP] }
total: { type: number, minimum: 0 }
purchaseOrderNumber: { type: [string, "null"] }
required: [invoiceNumber, currency, total, purchaseOrderNumber]
additionalProperties: false
attempts: 2
timeout: PT15SThis distinction gives the consumer a predictable property without pretending the invoice contained a purchase order number. If real invoices routinely omit required facts, give the operation an explicit missing-data outcome instead of asking the model to fill the gaps.
Run both from one program
With the .NET 10 SDK, create a console app using dotnet new console --framework net10.0. Add IntentSharp and IntentSharp.Catalog, both at version 1.0.1. See installation for package setup. Save the two YAML files in intents. In Program.cs, import System.Text.Json.Nodes, IntentSharp, IntentSharp.Catalog, IntentSharp.Results, and IntentSharp.Testing. Then add the call await RunExampleAsync(Path.GetFullPath("intents"), Console.Out); followed by the local function below. Run dotnet run from the project directory.
public static async Task RunExampleAsync(string folder, TextWriter output)
{
using var catalog = new FileIntentCatalog(
folder,
new FileIntentCatalogOptions { WatchForChanges = false });
if (catalog.Current.Problems.Count != 0)
throw new InvalidOperationException("An intent failed to load.");
var provider = new ScriptedProvider(
"""{"value":{"invoiceNumber":"000184","currency":"€","total":1860.00}}""",
"""{"value":{"invoiceNumber":"000184","currency":"EUR","total":1860.00}}""",
"""{"value":{"invoiceNumber":"INV-3307","currency":"USD","total":420.50,"purchaseOrderNumber":null}}""");
using var client = new IntentClientBuilder()
.UseProvider(provider)
.WithMemory(null)
.Build();
var runtime = new IntentRuntime(client, catalog);
var cases = new[]
{
(Name: "Acme.Invoice.Extract", Email: "Invoice 000184, total EUR 1860.00."),
(Name: "Globex.Invoice.Extract", Email: "Invoice INV-3307, total 420.50 USD.")
};
foreach (var item in cases)
{
AIResult<JsonNode> result = await runtime.RunAsync(item.Name, item.Email);
var expectedAttempts = item.Name == "Acme.Invoice.Extract" ? 2 : 1;
if (!result.Success || result.Value is not JsonObject value ||
result.Attempts.Count != expectedAttempts ||
(expectedAttempts == 2 && (value["invoiceNumber"]?.GetValue<string>() != "000184" ||
value["currency"]?.GetValue<string>() != "EUR")) ||
(expectedAttempts == 1 && (!value.ContainsKey("purchaseOrderNumber") ||
value["purchaseOrderNumber"] is not null)))
throw new InvalidOperationException($"Unexpected result for {item.Name}.");
output.WriteLine($"{item.Name}: accepted on attempt {result.Attempts.Count}; {result.Value?.ToJsonString()}");
}
if (provider.CallCount != 3)
throw new InvalidOperationException("Expected three scripted calls.");
}When you paste the method into a top-level program, omit the public modifier. Restoring packages requires NuGet access; running this example requires no model credentials and makes no model network call.
Acme.Invoice.Extract: accepted on attempt 2; {"invoiceNumber":"000184","currency":"EUR","total":1860.00}Globex.Invoice.Extract: accepted on attempt 1; {"invoiceNumber":"INV-3307","currency":"USD","total":420.50,"purchaseOrderNumber":null}Acme's first reply parses as JSON, but the currency symbol fails the schema. The second scripted reply uses EUR and passes on attempt two, preserving the leading zeros in 000184. Globex passes on attempt one, with a null purchase order number. This demonstrates application behavior with controlled replies. A live model can answer differently, and passing the schema does not establish factual correctness.
The part worth looking at
The call never branches on the result properties. The intent name selects the definition, and Catalog checks the result against that definition's schema. The branches in the example verify the two test cases. Adding another customer means adding a definition and configuring the application to select it. You still need to review the contract and any downstream mapping; you do not need a C# DTO solely to capture another set of extraction fields.
Use the Catalog path for local validation of a supported JSON Schema contract. The core also accepts a runtime schema on TransformAsync; that overload checks the JSON response envelope and non-null value, so supply local validators for schema constraints you need to enforce there.
Next in the series: let AI help shape the data your application needs.