Skip to main content

Annotated Results

AnnotatedResult Class

Use this class to return function metadata, or other data, that is not intended to be included with the main results.

For example, source citations can be included by using this object as a wrapper for the real results.

from openbb_core.provider.abstract.annotated_result import AnnotatedResult

Initialize the class with two objects.

  • result: Any
    • Serializable results - i.e, list[dict]
  • metadata: dict
    • JSON-encodable dictionary

How To Use

important

The class is used in conjunction with the ProviderInterface.

In the provider's Fetcher.transform_data method, wrap and annotate the output like below.

    @staticmethod
def transform_data(
query: FredSeriesQueryParams,
data: dict,
**kwargs: Any,
) -> AnnotatedResult[list[FredSeriesData]]:
"""Transform data."""
records = data.get("results", [])
metadata = data.get("metadata", {})

return AnnotatedResult(
result=[FredSeriesData.model_validate(r) for r in records],
metadata=metadata,
)

Output

When the pattern above is used, the metadata dictionary is returned to, output.extra["results_metadata"].