| title | Annotated Results | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| sidebar_position | 4 | |||||||||||||
| description | This guide provides instructions for returning extra response metadata from Provider extension models. Use this class to include important citations, credits, or other dictionary-like items that should not be included in table or chart data. | |||||||||||||
| keywords |
|
import HeadTitle from '@site/src/components/General/HeadTitle.tsx';
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 AnnotatedResultInitialize the class with two objects.
- result: Any
- Serializable results - i.e,
list[dict]
- Serializable results - i.e,
- metadata: dict
- JSON-encodable dictionary
:::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,
)When the pattern above is used, the metadata dictionary is returned to, output.extra["results_metadata"].