.NET: credit assessment example
Instrument an ASP.NET Core request and add explicit business and AI observations.
#1. Install the packages
Use the local NuGet source supplied by the portal. ASP.NET Core applications use Sigillum.Finans.Sdk.AspNetCore; workers and console applications use the core package.
dotnet add package Sigillum.Finans.Sdk.AspNetCore --version 0.11.0 --source ./packagesResolve dependencies through an approved NuGet source. Keep the service configuration outside public files and source control. The downloadable project reads its absolute path from SIGILLUM_CONFIG.
using System.Text.Json;
using Sigillum.Finans.Sdk;
var builder = WebApplication.CreateBuilder(args);
var config = Path.GetFullPath(Environment.GetEnvironmentVariable("SIGILLUM_CONFIG")
?? throw new InvalidOperationException("Set SIGILLUM_CONFIG to the absolute configuration path."));
builder.Services.AddSigillum(config);
builder.Services.AddHttpClient();
var app = builder.Build();
app.UseSigillum();
app.MapPost("/loans/evaluate", (LoanInput input, SigillumClient observer) =>
{
if (input.Amount <= 0 || input.Months <= 0 || input.MonthlyIncome <= 0)
return Results.BadRequest(new { error = "Amount, months and monthly income must be positive." });
observer.SetReferences(new SdkReferences(
SessionRef: input.RequestRef,
External: [new SdkExternalReference("demo.loan", input.RequestRef)]));
// Synthetic teaching rule: excludes interest/fees and is not a lending decision.
using var step = observer.BeginStep("affordability-rule");
var payment = decimal.Round(input.Amount / input.Months, 2);
var ratio = payment / input.MonthlyIncome;
var outcome = new { input.RequestRef, monthlyPayment = payment,
incomeRatio = ratio, eligible = ratio <= 0.35m, demonstration = true };
observer.Policy(JsonSerializer.SerializeToUtf8Bytes(new {
name = "demo-income-ratio", version = "1", threshold = 0.35m }));
observer.Explanation(JsonSerializer.SerializeToUtf8Bytes(new {
method = "deterministic-demo", reason = "monthlyPayment / monthlyIncome",
value = ratio, threshold = 0.35m }));
observer.Custom("loan.result", JsonSerializer.SerializeToUtf8Bytes(outcome));
observer.Source(JsonSerializer.SerializeToUtf8Bytes(new {
reference = input.RequestRef, type = "demo-result" }),
[new SdkAttachment("result", "application/json", "comparison.originalContent",
JsonSerializer.SerializeToUtf8Bytes(outcome))]);
return Results.Ok(outcome);
});
app.MapGet("/sdk-status", (SigillumClient sdk) => sdk.Status);
app.Run("http://127.0.0.1:5108");
record LoanInput(string RequestRef, decimal Amount, int Months, decimal MonthlyIncome);
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup><TargetFramework>net8.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
<ItemGroup><PackageReference Include="Sigillum.Finans.Sdk.AspNetCore" Version="0.11.0" /></ItemGroup>
</Project>#2. Register the SDK
builder.Services.AddSigillum() registers the SDK. app.UseSigillum() must run before handlers that consume the request body. IHttpClientFactory clients receive the supplied handler. Use SigillumHttpHandler for a directly constructed HttpClient. Preserve existing authentication and security middleware.
#3. Record the assessment
The example accepts an amount and income at POST /loans/evaluate. BeginStep creates the actual assessment step. It explicitly records the applied policy, explanation, business result and source attachment. Model and other AI categories are covered separately in the additional-observation examples. The calculation is a deterministic teaching rule, not a production credit-scoring model.
#4. Add observations
Model, Classification, Retrieval, Tool, Embedding, Inference, Evaluation, Policy and Explanation are the AI convenience methods. Custom and Source carry additional data and source content. TryRecord provides the family/kind/raw-JSON interface. SetReferences adds optional person, session and external references.
Use existing raw UTF-8 JSON. Do not traverse business-object getters solely for observation. A successful capture result means bounded-memory acceptance, not central sealed delivery.
#5. Handle errors and asynchronous work
SdkOperation.Fail(exception) records the safe error type. Preserve application exception handling and cancellation. ObserveAiAsync executes the real call once. Do not add network flushes or delivery waits to the business request path.
#6. Run the project
Extract the ZIP and restore the supplied SDK from the local package source. Set SIGILLUM_CONFIG to the absolute service-configuration path and follow the README restore and run commands. Configure POST /loans/evaluate as the portal entry point. The sample binds to localhost.
