From 787e8ff457869cba61da2a9714d690a79146a2bd Mon Sep 17 00:00:00 2001 From: hazeone <709547807@qq.com> Date: Tue, 25 Nov 2025 11:26:01 +0800 Subject: [PATCH] add model_validator in TradeDecisionItem --- .../valuecell/agents/common/trading/models.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/python/valuecell/agents/common/trading/models.py b/python/valuecell/agents/common/trading/models.py index 80cb34412..163a8c283 100644 --- a/python/valuecell/agents/common/trading/models.py +++ b/python/valuecell/agents/common/trading/models.py @@ -547,6 +547,23 @@ class TradeDecisionItem(BaseModel): default=None, description="Optional natural language rationale" ) + # TODO: Remove this validator when the model supports InstrumentRef. + @model_validator(mode="before") + @classmethod + def _normalize_instrument(cls, data): + """Normalize instrument field: allow string shorthand for InstrumentRef. + + Some LLMs return instrument as a plain string (e.g., "ETH/USDT") instead + of an object {"symbol": "ETH/USDT"}. This validator handles both formats. + """ + if not isinstance(data, dict): + return data + values = dict(data) + instrument = values.get("instrument") + if isinstance(instrument, str): + values["instrument"] = {"symbol": instrument} + return values + class TradePlanProposal(BaseModel): """Structured output before rule normalization."""