Home
AlfaStrakhovanieClient

AI analyst for insurance portfolios

An LLM agent turns questions about sales, renewals and claims into analytical tool calls: selecting an analysis, specifying filters and table joins, then explaining the computed result.

Tool calling for insurance analytics

Built the LangGraph orchestration, typed calls and analytical engine. Applied SFT, GRPO and SGR to improve the model’s use of tools.

STACK

  • LangGraph
  • Pydantic
  • Tool calling
  • SFT
  • GRPO
  • SGR
  • ClickHouse
  • Python / pandas

From a question to a tool call and a calculation

LLM → TYPED CALL → EXECUTION → RESULTPan the diagram or select a stage below
From a question to a tool call and a calculation01 / CONTEXT FOR ANALYSIS SELECTIONQuestion + historycurrent request · periodAnalysis cataloguedescription · available columnsMetric semanticsdefinitions · types · tree02 / THE MODEL FORMS THE CONTRACT — CODE EXECUTES THE ANALYSISStructured analytical callanalysis · table · columnsfilter · group_by · aggregatesjoins · having · sortLLM · structured outputPydantictypes · structure · join modeCatalogue executorpandas · portfolio tablesJSON / schema errorfallback03 / THE COMPUTED RESULT RETURNS TO THE CONVERSATIONComputed resultseparate state fieldAnswer + recommendationsdata · meaning · display orderReply to the agentafter wording review04 / IMPROVING TOOL SELECTION AND CALL FORMATIONSFTtool-use fine-tuningGRPObehavior optimizationSGRstructured reasoning05 / PARALLEL PATH: ANALYTICAL ENGINE AND PORTFOLIO CARDSMarts + metadataClickHouse · metric treeRecursive factor attributionsubstitutions · contributions · residualPortfolio cardsdeviation · drivers · questionsWhat-ifrecalculate dependent branchesA scenario preserves otherobserved values.

The model selects an analysis and its parameters; the catalogue supplies the executable operation. The numerical result feeds a separate response stage. Below: tool-use adaptation and the parallel calculation path for cards.

DIAGRAM NOTE

Public reconstruction of the operating principles. Field names are generalized; internal prompts, formulas, norms and customer data are omitted.

Scroll diagram ↔
TOOL CALLING

What goes into a tool call

A follow-up such as “and for the previous month?” requires recovering the subject, changing the period and calculating a fresh result. I connected conversation history, business semantics and an executable analysis contract.

01

Catalogue-grounded selection

The catalogue covers metrics and norms, claim detail, renewal selection and custom table queries. The model receives analysis descriptions and output fields. LangGraph routes the request to calculation, metric explanation or clarification.

02

Typed arguments

Pydantic defines the call structure: analysis, table, columns, filter, grouping, aggregates, having and sorting. Separate join instructions carry the join key and mode. The executor checks that the analysis exists in the catalogue.

03

One tool-call representation

Built an adapter for native function calls and JSON calls embedded in model text, normalizing names and arguments into one structure. Analysis selection cleans formatting artifacts and parses the JSON with Pydantic; a parse failure sends the conversation to a fallback.

04

Separate execution and response stages

Python/pandas executes the selected catalogue code on registered portfolio tables. The result is stored separately from message history. Subsequent nodes use it for the answer and recommendations; a separate stage then reviews the response wording.

Tools by task

Orchestration & calls

LangGraph · LangChain · Pydantic · JSON Schema

Config-defined graph, routing, typed parameters and tool-call normalization.

Tool-use adaptation

SFT · GRPO · SGR

Fine-tuning, behavior optimization and structured selection of analytical actions.

Analysis execution

Python · pandas · ClickHouse · SQL

Executable analysis catalogue; filters, joins, grouping, aggregation and sorting over portfolio tables.

Calculations & interface

Metric trees · Sequential substitution · What-if · FastAPI

Recursive factor contributions, dependent-branch recalculation, cards and a conversational interface.

Architecture, step by stepHighlighted data flow and technical walkthrough

Tool calling: context, contract and execution

Scroll to highlight each stage and its data flow.

01 / 07
Tool calling: context, contract and executionMODEL CONTEXTSTRUCTURED CALLRESULT AND RESPONSEANALYTICAL TOOL-USE ADAPTATIONSEPARATE CALCULATION PATH FOR CARDSQuestion & historylatest message · periodAnalysis cataloguepurpose · output columnsData semanticsdescriptions · types · metricsLLM adapternative calls + JSON → name / argsRoute selectionLiteral: allowed next statesSelect & parameterizefilter · join · group · agg · sortParse against schemaPydantic · parameter typesCatalogue executionkey lookup · Python / pandasFormat errorfallback without running analysisPortfolio tablesClickHouse · customer · policy ·periodResult in stateseparate from message historyExplain the resultdata + metric semanticsRecommendationsa separate stage after the answerReply to the userwording reviewSFT · GRPO · SGRtraining and structuring tool useAnalytical call qualitytool selection + argument formationMetric treeobservations · dependencies · baselineFactor contributionssubstitution · root units · residualPortfolio cardsdeviation · contribution · nextquestionWhat-ifrecalculate affected branches

Pan to explore the diagram ↔

DataModelStateEvaluation

Ground the request in available analytics

01

Ground the request in available analytics

The router receives conversation history and selects an allowed route. For analysis, the model sees operations, available columns, metric definitions and the period, giving follow-up questions their domain context.

02

Form the analytical contract

The model output specifies the analysis and calculation parameters: table, columns, filter, grouping, aggregations, having, sorting and join instructions. Pydantic checks structure and types; the executor looks up the key in the analysis catalogue.

03

Normalize tool-call representations

The LLM adapter supports native function calls and JSON calls in text, normalizing names and arguments. Analysis selection cleans and parses JSON against its schema; unrecognized formats take a fallback path.

04

Execute against portfolio tables

The execution node loads registered tables for the agent, supplies parameters and runs selected catalogue code. It supports specialized analyses and a general path for pandas filtering, joining, grouping and aggregation.

05

Bring the result back into the conversation

The numerical result remains in a separate state field. The answer uses the data, metric definitions and sort order. Recommendations and wording review follow as separate stages.

06

Improve the model’s use of tools

Applied SFT for fine-tuning, GRPO for behavior optimization and SGR for structured reasoning. The objective was better analytical tool selection and call formation.

07

Explain metric changes through cards

A separate calculation path builds a metadata-defined metric tree. Recursive sequential substitution expresses contributions in root units and retains a residual. What-if recalculates dependent branches; cards expose deviations and their contributing factors.