fix(tools): accept only the statement frequencies the vendors serve (#1593)

- freq is annual or quarterly in the tool schema; any other word is sent back to the model instead of being served annual figures under that word
This commit is contained in:
Yijia-Xiao
2026-10-27 08:01:21 +00:00
parent d46c052278
commit bf7f4b55a3
2 changed files with 12 additions and 4 deletions
+8
View File
@@ -141,6 +141,14 @@ def test_an_unpadded_date_reaches_the_vendor_in_canonical_form():
assert args[-2:] == ("2026-07-01", "2026-07-03")
@pytest.mark.unit
@pytest.mark.parametrize("tool", [tools.get_balance_sheet, tools.get_cashflow, tools.get_income_statement])
def test_a_statement_frequency_is_one_the_vendors_serve(tool):
# Any other word was served annual figures under the word asked for.
schema = tool.tool_call_schema.model_json_schema()["properties"]["freq"]
assert schema["enum"] == ["annual", "quarterly"]
@pytest.mark.unit
def test_direct_call_without_state_is_unchanged():
with mock.patch.object(tools, "route_to_vendor", return_value="ok") as routed:
+4 -4
View File
@@ -4,7 +4,7 @@ Each dated tool takes the run's ``trade_date`` from graph state (``InjectedState
and never serves data past it, whatever date the model asks for.
"""
from typing import Annotated
from typing import Annotated, Literal
from langchain_core.tools import tool
from langgraph.prebuilt import InjectedState
@@ -114,7 +114,7 @@ def get_fundamentals(
@tool
def get_balance_sheet(
ticker: Annotated[str, InjectedState("company_of_interest")],
freq: Annotated[str, "reporting frequency: annual/quarterly"] = "quarterly",
freq: Annotated[Literal["annual", "quarterly"], "reporting frequency"] = "quarterly",
curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"] = None,
trade_date: Annotated[str, InjectedState("trade_date")] = "",
) -> str:
@@ -133,7 +133,7 @@ def get_balance_sheet(
@tool
def get_cashflow(
ticker: Annotated[str, InjectedState("company_of_interest")],
freq: Annotated[str, "reporting frequency: annual/quarterly"] = "quarterly",
freq: Annotated[Literal["annual", "quarterly"], "reporting frequency"] = "quarterly",
curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"] = None,
trade_date: Annotated[str, InjectedState("trade_date")] = "",
) -> str:
@@ -152,7 +152,7 @@ def get_cashflow(
@tool
def get_income_statement(
ticker: Annotated[str, InjectedState("company_of_interest")],
freq: Annotated[str, "reporting frequency: annual/quarterly"] = "quarterly",
freq: Annotated[Literal["annual", "quarterly"], "reporting frequency"] = "quarterly",
curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"] = None,
trade_date: Annotated[str, InjectedState("trade_date")] = "",
) -> str: