Files
AgenticCode/openspec/changes/archive/2026-04-06-update-extraction-schema/tasks.md
local 5b027eb0db feat: add extraction schema, sidebar nav, few-shot prompting, and prompt settings
Overhaul extraction pipeline with new TradeItem model, conversation flow,
and dedicated extraction endpoint. Add sidebar navigation with NavMenu
component and landing page. Introduce few-shot prompting service and
tests. Add prompt settings and email upload specs. Update OpenSpec
tooling with improved export-spec and extract-feature commands. Archive
completed changes and export full specs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 23:39:23 +01:00

3.0 KiB

1. Replace Shared Models

  • 1.1 Create TradeItem.cs in Shared/Models with fields: Valuedate (string), Counterparty (string), LegalEntity (string?), TradeId (long), DisplayCcy (string), Pv (double), Breakclause (string). Add [JsonPropertyName] attributes for snake_case serialization.
  • 1.2 Create ExtractionResult.cs in Shared/Models with List<TradeItem> Items property
  • 1.3 Delete the old ExtractedFields.cs
  • 1.4 Update ValidationResult.cs to support candidate lists — add List<CandidateMatch>? Candidates property for disambiguation results (each with Name and LegalEntity fields)

2. Configure External API HttpClients

  • 2.1 Add ExternalApis section to appsettings.json with base URLs for counterparty, trade, and currency APIs
  • 2.2 Create typed HttpClient service CounterpartyApiClient with LookupAsync(string name) method returning candidate tuples
  • 2.3 Create typed HttpClient service TradeApiClient with ValidateAsync(long tradeId) method
  • 2.4 Create typed HttpClient service CurrencyApiClient with ValidateAsync(string currencyCode) method
  • 2.5 Register all typed HttpClients in Program.cs via AddHttpClient<T>() with base URLs from configuration

3. Rewrite ExtractionPlugin

  • 3.1 Replace ExtractionPlugin.ValidateExtractedFields() with LookupCounterparty(string name) — calls CounterpartyApiClient, returns candidate list as JSON. Include [KernelFunction] and [Description] attributes explaining the tool returns candidates for disambiguation.
  • 3.2 Add ValidateTrade(long tradeId) method — calls TradeApiClient, returns valid/invalid result as JSON
  • 3.3 Add ValidateCurrency(string currencyCode) method — calls CurrencyApiClient, returns valid/invalid result as JSON
  • 3.4 Add ValidateSchema(string extractionResultJson) method — validates the full ExtractionResult JSON against TradeItem schema locally (required fields present, correct types, breakclause is Y or N)
  • 3.5 Inject typed HttpClients into ExtractionPlugin via constructor. Register ExtractionPlugin in DI with its dependencies.
  • 3.6 Add error handling in each tool method — catch HttpRequestException, return structured error JSON instead of throwing

4. Update Controller

  • 4.1 Update ChatController.Post() — no changes needed, DI resolution via GetRequiredService works with scoped registration to use the new ExtractionPlugin constructor (pass DI-resolved instance with HttpClients)

5. Update Tests

  • 5.1 Remove or rewrite tests referencing old ExtractedFields schema
  • 5.2 Add unit tests for ValidateSchema method against TradeItem (valid, missing fields, wrong types)
  • 5.3 Add unit tests for ExtractionPlugin tool methods with mocked HttpClients (success, error, multi-candidate responses)

6. Build and Verify

  • 6.1 Build the solution (dotnet build) and confirm no compilation errors
  • 6.2 Run all tests (dotnet test) and confirm they pass