---
title: "See which address fields came from a model in C#"
url: https://recursiveai.org/onecontact/cookbook/inspect-address-rule-vs-model-fields/
description: "See which postal address fields came from a rule or a trained model in C#. Read OneContact’s per-field source and locate the original text."
version: "1.1.0"
---

# See which address fields came from a model in C#

**OneContact** is a free, open-source contact data library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies, no network access.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneContact.Models) · [GitHub](https://github.com/recursive-ai-oss/onecontact-csharp) · [Docs](https://recursiveai.org/onecontact/docs/) · [Download example (.zip)](https://recursiveai.org/onecontact/cookbook/inspect-address-rule-vs-model-fields/inspect-address-rule-vs-model-fields.zip)

Read `ParseDetail.Fields` to see where the parser used a rule and where it used the model.

```shell
dotnet add package RecursiveAI.OneContact.Models
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using System.Buffers;
using RecursiveAI.OneContact;

var text = "Alex Example\n123 Main St\n"
    + "Fort Worth TX 76102";
var status = PostalAddress.TryParse(
    text, Region.US, out _, out var detail);
if (status != OperationStatus.Done)
    throw new FormatException(
        detail.PrimaryReason.Id);
foreach (var field in detail.Fields)
    Console.WriteLine(
        $"{field.Name}: {field.Source}");
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onecontact/cookbook/inspect-address-rule-vs-model-fields/inspect-address-rule-vs-model-fields.zip) and `dotnet run`.

```text
recipient: Model
street.house-number: Rule
street.name: Rule
street.type: Rule
locality: Rule
admin-area: Rule
postal-code: Rule
```

Check for `OperationStatus.Done` before reading the fields; the example reports the parser’s reason ID if the parse fails.

## Variations

For a review screen, show just the original text of fields the model read. Use each field’s offsets against the original input, not the formatted address:

```csharp
using System.Buffers;
using RecursiveAI.OneContact;

const string text =
    "Alex Example\n123 Main St\nFort Worth TX 76102";
var status = PostalAddress.TryParse(
    text, Region.US, out _, out var detail);
if (status != OperationStatus.Done)
    throw new FormatException(detail.PrimaryReason.Id);

foreach (var field in detail.Fields)
{
    if (field.Source != DecisionSource.Model)
        continue;
    var span = field.Span;
    Console.WriteLine(text.Substring(span.Start, span.Length));
}
```

```text
Alex Example
```

## Related recipes

- [Parse messy US and Canadian addresses in C#](https://recursiveai.org/onecontact/cookbook/enable-us-canada-address-model-fallback/)
- [Parse an international address with a country hint in C#](https://recursiveai.org/onecontact/cookbook/parse-tier2-address-with-country-hint/)
- [Parse a postal address in C#](https://recursiveai.org/onecontact/cookbook/parse-postal-address/)

## The short answer

Use the `PostalAddress.TryParse` overload that returns both an `OperationStatus` and a `ParseDetail`. After `OperationStatus.Done`, read `detail.Fields`. A field whose `Source` is `DecisionSource.Model` was decided by the model; `DecisionSource.Rule` means a rule or lookup table decided it. Installing the model package does not make every parsed field model-derived.

## How do I trace parsed address components back to the original string?

Use `ParsedField.Name` to find the component and `ParsedField.Span` to locate it. The span gives `Start` and `Length` in UTF-16 code units, the units used by `string.Substring`. The variation uses those offsets to recover `Alex Example`, with the original capitalization. Don’t apply them to `address.Canonical`: formatting may insert separators, change the case, or otherwise move the text. Keep the input string with the parse details if you need to reconstruct what someone entered.

The source and the formatted value answer different questions. The output’s `recipient: Model` says how the parser decided the role of the leading line, not that it generated a new recipient. Compare that with `locality: Rule`: the rules already recognized Fort Worth as the locality, so the model did not replace it. These distinctions are useful in review interfaces that highlight fields needing a second look without marking an entire row as a guess.

## What does an address parser’s confidence score tell me?

`ParsedField.Confidence` ranges from 0 to 1. It’s exactly 1 for a rule decision; a model field carries the confidence reported by the model. Use `Source`, not a confidence threshold, to distinguish the two. The score describes how the parser assigned a field. It doesn’t tell you that the person lives there, that the street number exists, or that a postal service will deliver to it.

For a review queue, keep parse failure separate from a successful parse with a model-derived field. A failure has a reason you can show or log; a successful parse can contain a mix of rule and model decisions, as the example does. The [parse API](https://recursiveai.org/onecontact/docs/api-shapes/) describes reason codes, and the [model notes](https://recursiveai.org/onecontact/docs/models/) describe how field confidence is obtained.
