Skip to main content

Disabling Output Validation

In some cases, it may be desirable to disable output validation for a custom router endpoint. The example below demonstrates how to do it within your own custom router path.

important

This section refers to settings available beginning OpenBB v4.4.0

In boths functions, the output will be typed as "Any", regardless of what the return definition states.

Within the @router.command decorator, add the keyword argument:

no_validate = True

Example

This example assumes that ficticious extensions have been defined and installed.

from datetime import datetime

from openbb_core.app.model.command_context import CommandContext
from openbb_core.app.model.example import APIEx, PythonEx
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.provider_interface import (
ExtraParams,
ProviderChoices,
StandardParams,
)
from openbb_core.app.query import Query
from openbb_core.app.router import Router
from openbb_core.provider.abstract.data import Data

router = Router(prefix="", description="Some OpenBB Router Extension.")

# This uses the Provider Interface.
@router.command(
model="SomeModel",
no_validate=True,
examples=[
APIEx(parameters={"provider": "some_provider"}),
PythonEx(
description="Say Hello.",
code=[
"result = obb.some_extension.some_provider_function()",
],
),
],
)
async def some_provider_function(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[Data]:
"""Some function using the Provider Interface."""
obbject = await OBBject.from_query(Query(**locals()))

new_output = []
results = obbject.results

# Do something with results and append to `new_output` list.

return new_output


# This is a standard router "get" command.
@router.command(
methods=["GET"],
no_validate=True
examples=[
PythonEx(
description="Say Hello.",
code=[
"result = obb.some_extension.hello()",
],
),
],
)
async def hello() -> (
Any
):
"""Hello World."""
return {
datetime.now().strftime(
"%Y-%m-%d"
): "Hello from the Empty Router extension!"
}

On this page