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>
This commit is contained in:
local
2026-04-06 23:39:23 +01:00
parent 7a5c22593a
commit 5b027eb0db
83 changed files with 4242 additions and 296 deletions

View File

@@ -0,0 +1,25 @@
<html>
<body>
<p>Subject: RE: AG Inflation swaps CVA Request</p>
<p>Ovi,</p>
<p>Hope you are well.</p>
<p>Could you kindly share indicative CVA for the below two inflation swaps, assuming the counterparty is Assured Guaranty UK Limited (formerly Assured Guaranty (Europe) Ltd), which is rated AA- by S&amp;P and A1 by Moody's please?</p>
<p>OB 27/11/2025</p>
<p><b>Swap 1 please price standalone</b></p>
<table border="1">
<tr><th></th><th>CSA</th><th>Murex</th><th>PV (£)</th></tr>
<tr><td>Coupon Leg</td><td>BTMU_JPY</td><td>79353083</td><td>4,562,456</td></tr>
<tr><td>APD leg</td><td>BTMU_JPY</td><td>79353084</td><td>76,985,170</td></tr>
</table>
<p>Total PV: 81,547,626</p>
<p><b>Swap 2 please price standalone</b></p>
<table border="1">
<tr><th></th><th>CSA</th><th>Murex</th><th>PV (£)</th></tr>
<tr><td>Coupon Leg</td><td>BTMU_JPY</td><td>79353093</td><td>1,663,261</td></tr>
<tr><td>APD leg</td><td>BTMU_JPY</td><td>79353094</td><td>41,333,773</td></tr>
</table>
<p>Total PV: 42,997,034</p>
<p>Many thanks.</p>
<p>Kind regards,</p>
</body>
</html>

View File

@@ -0,0 +1,36 @@
{
"items": [
{
"valuedate": "27/11/2025",
"counterparty": "Assured Guaranty UK Limited (formerly Assured Guaranty (Europe) Ltd)",
"trade_id": 79353083,
"display_ccy": "GBP",
"pv": 4562456,
"breakclause": "N"
},
{
"valuedate": "27/11/2025",
"counterparty": "Assured Guaranty UK Limited (formerly Assured Guaranty (Europe) Ltd)",
"trade_id": 79353084,
"display_ccy": "GBP",
"pv": 76985170,
"breakclause": "N"
},
{
"valuedate": "27/11/2025",
"counterparty": "Assured Guaranty UK Limited (formerly Assured Guaranty (Europe) Ltd)",
"trade_id": 79353093,
"display_ccy": "GBP",
"pv": 1663261,
"breakclause": "N"
},
{
"valuedate": "27/11/2025",
"counterparty": "Assured Guaranty UK Limited (formerly Assured Guaranty (Europe) Ltd)",
"trade_id": 79353094,
"display_ccy": "GBP",
"pv": 41333773,
"breakclause": "N"
}
]
}

View File

@@ -0,0 +1,14 @@
<html>
<body>
<p>Subject: CVA quote USD interest rate swap</p>
<p>Hi team,</p>
<p>Please provide CVA for the following single interest rate swap with Deutsche Bank AG, London Branch.</p>
<p>Value date: 15/03/2026</p>
<table border="1">
<tr><th></th><th>CSA</th><th>Murex</th><th>PV ($)</th></tr>
<tr><td>Fixed Leg</td><td>DB_USD</td><td>81200451</td><td>12,750,000</td></tr>
</table>
<p>Thanks,</p>
<p>Sarah</p>
</body>
</html>

View File

@@ -0,0 +1,12 @@
{
"items": [
{
"valuedate": "15/03/2026",
"counterparty": "Deutsche Bank AG, London Branch",
"trade_id": 81200451,
"display_ccy": "USD",
"pv": 12750000,
"breakclause": "N"
}
]
}

View File

@@ -0,0 +1,15 @@
<html>
<body>
<p>Subject: RE: CVA Cross-currency swap with break clause</p>
<p>Dear Ovi,</p>
<p>Could you provide indicative CVA for the below cross-currency swap with Barclays Bank PLC? Note: this trade has a break clause at the 5-year point.</p>
<p>OB 01/06/2025</p>
<table border="1">
<tr><th></th><th>CSA</th><th>Murex</th><th>PV (€)</th></tr>
<tr><td>EUR Leg</td><td>BARC_EUR</td><td>77890112</td><td>8,421,300</td></tr>
<tr><td>GBP Leg</td><td>BARC_EUR</td><td>77890113</td><td>22,105,800</td></tr>
</table>
<p>Thanks,</p>
<p>Mark</p>
</body>
</html>

View File

@@ -0,0 +1,20 @@
{
"items": [
{
"valuedate": "01/06/2025",
"counterparty": "Barclays Bank PLC",
"trade_id": 77890112,
"display_ccy": "EUR",
"pv": 8421300,
"breakclause": "Y"
},
{
"valuedate": "01/06/2025",
"counterparty": "Barclays Bank PLC",
"trade_id": 77890113,
"display_ccy": "EUR",
"pv": 22105800,
"breakclause": "Y"
}
]
}

View File

@@ -0,0 +1,39 @@
You are a trade data extraction agent. Your task is to extract structured trade data from sales emails (typically CVA pricing requests) and return the result as JSON.
## Output Schema
Return a JSON object with an "items" array. Each item represents one trade leg and has these fields:
- valuedate (string): The value/observation date in dd/MM/yyyy format. Look for "OB", "Value date", or similar date references in the email.
- counterparty (string): The full legal name of the counterparty as stated in the email prose.
- trade_id (integer): The Murex trade identifier. Each trade leg has a unique Murex ID.
- display_ccy (string): The ISO currency code derived from the email. Map currency symbols: £ → GBP, $ → USD, € → EUR. If stated as an ISO code, use it directly.
- pv (number): The present value as a plain number. Remove commas and currency symbols. Do not round.
- breakclause (string): "Y" if the email mentions a break clause for the trade, "N" otherwise. Default to "N" if not mentioned.
The legal_entity field is NOT included in your output. It is populated later via a counterparty lookup tool.
## Mapping Rules
1. FLATTEN: Each swap leg with a unique Murex trade ID becomes a separate item. A swap with a Coupon Leg (Murex 123) and an APD leg (Murex 456) produces two items.
2. DATE: Parse the value date from context (e.g., "OB 27/11/2025" means valuedate is "27/11/2025"). Always output in dd/MM/yyyy format.
3. COUNTERPARTY: Use the full legal name exactly as written in the email, including any parenthetical former names.
4. CURRENCY: Derive from the PV column header or context. "PV (£)" means GBP. "PV ($)" means USD. "PV (€)" means EUR.
5. PV: Strip formatting (commas, spaces, currency symbols) and output as a plain number.
6. BREAKCLAUSE: Default to "N". Only set to "Y" if the email explicitly mentions a break clause for the trade.
## Output Format
Return ONLY valid JSON. Do not include markdown code fences or explanatory text. Example:
{"items":[{"valuedate":"27/11/2025","counterparty":"Example Corp","trade_id":12345,"display_ccy":"GBP","pv":1234567,"breakclause":"N"}]}
## After Extraction
After producing the initial extraction, use the available validation tools:
- lookup_counterparty: Look up the counterparty name to find matching legal entities.
- validate_trade: Verify each trade ID exists.
- validate_currency: Confirm each currency code is valid.
- validate_schema: Validate the complete extraction result.
If a tool returns multiple candidates (e.g., counterparty lookup), present them to the user as a numbered list and ask which one to use. If a tool indicates an error, attempt to fix the extraction or ask the user for clarification.