Skip to content

Update tools to more gracefully handle errors#110

Merged
matthew-rosen-12 merged 24 commits intomainfrom
mhr.estimates.errors
Mar 30, 2026
Merged

Update tools to more gracefully handle errors#110
matthew-rosen-12 merged 24 commits intomainfrom
mhr.estimates.errors

Conversation

@matthew-rosen-12
Copy link
Copy Markdown
Contributor

@matthew-rosen-12 matthew-rosen-12 commented Mar 19, 2026

Update estimates tools to gracefully handle errors
Use PostResponse consistently
raise responses for status if the response does not include an errors field (all GET responses except estimates)

michellekeoy and others added 12 commits March 19, 2026 16:39
* draft

* complete TODOs

* change order

* test full responses

* update tool tests

* add object tests

* clean up tests

* remove aliases

* remove from all tools

* update change log

* revert

* Add new tools to ALL_TOOLS

* draft

* complete TODOs

* change order

* test full responses

* update tool tests

* add object tests

* clean up tests

* remove aliases

* remove from all tools

* update change log

* revert

* pull async changes

* rebase

* update changlog

---------

Co-authored-by: Michelle Keoy <michelle.keoy@kensho.com>
Co-authored-by: matthew-rosen-12 <matthewhrosen@gmail.com>
Co-authored-by: jsanders-py <jordanmsanders17@gmail.com>
periods: dict[str, EstimatesPeriodData]


class EstimatesResp(RespWithErrors):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a separate EstimatesResp model instead of using PostResponse[Estimates] because the estimates response should only contain a single result. I thought it was fine to get rid of the result key

periods: dict[str, StatementPeriodData] # period -> statement and period data


class StatementsBatchResp(BaseModel):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be replaced by PostResponse[Statements] since errors exists as an attribute on PostResponse[Statements] until serialization

@matthew-rosen-12 matthew-rosen-12 force-pushed the mhr.estimates.errors branch 5 times, most recently from 6edb9ab to 44849e2 Compare March 23, 2026 19:46
@matthew-rosen-12 matthew-rosen-12 changed the title Update estimates tools to gracefully handle errors Update tools to more gracefully handle errors Mar 24, 2026
@matthew-rosen-12 matthew-rosen-12 marked this pull request as ready for review March 25, 2026 21:37
@matthew-rosen-12
Copy link
Copy Markdown
Contributor Author

matthew-rosen-12 commented Mar 25, 2026

I did QA for the tools locally. The tools work as expected, except that for the below tools, identifiers without data get mapped to empty data in results:
get_company_description_from_identifiers
get_competitors_from_identifiers
get_earnings_from_identifiers
get_rounds_of_funding_from_identifiers
get_funding_summary_from_identifiers

For example, the get_company_description_from_identifiers tool returns:
{"results":{"COMPANY_WITH_NO_DATA":""}}

whereas the get_consensus_target_price_from_identifiers tool returns:
{"results":{},"errors":["COMPANY_WITH_NO_DATA: No results found."]}

We could change the corresponding APIs to raise 404 errors if no data was found in order to change those empty data-mappings to an error; no additional changes to the client would be needed.

result: ConsensusTargetPrice | None = None
error: str | None = None

@model_serializer(mode="wrap")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two functions get defined a few times.

Could we handle them with generics? Something like

  class SingleResultResp(BaseModel, Generic[T]):
      """Base response model that unwraps a single result from the API's multi-result format."""

      result: T | None = None
      error: str | None = None

and

class EstimatesResp(SingleResultResp[Estimates]):

Or was one of the goals of the PR to reduce the usage of PostResponse?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I will update to handle with generics. I wasn't sure if I should abstract out a class like that since the Estimates endpoints are the only endpoints (and will continue to be the only endpoints?) that return a single response in the results / errors format

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@matthew-rosen-12 matthew-rosen-12 merged commit ad1dc85 into main Mar 30, 2026
6 checks passed
@matthew-rosen-12 matthew-rosen-12 deleted the mhr.estimates.errors branch March 30, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants