Skip to main content

Using mock deployments in Snowflake

If you're integrating Modelbit Deployments into your data pipeline or dbt jobs, sometimes you may want to skip calling the model during tests or development. Modelbit provides mock functions for these situations.

Use session variables to tell Modelbit whether to call the predictive model or to return static data instead. Setting MODELBIT_MOCK to 'MOCK' tells Modelbit to skip calling the API during this session:

set MODELBIT_MOCK = 'MOCK';
select ext_example_func_123(...); -- won't call predictive model

If you don't set MODELBIT_MOCK, or unset it, Modelbit will follow the default behavior and call the predictive model:

unset MODELBIT_MOCK;
select ext_example_func_123(...); -- will call predictive model

Specifying the mock return value

By default, calling a deployment in MOCK mode will return null. You can change the deployment to return another value by setting snowflake_mock_return_value when calling mb.deploy.

For example, suppose we want to supply a mock value for the spaCy deployment that splits paragraphs into sentences:

mb.deploy(segment_sentences,
snowflake_mock_return_value=["Fish live in the ocean.", "Birds live in trees."])

Mocked return values can be any value you choose as long as they conform to the return type of the inference function. For example, if your inference function returns integers the mock value must also be an integer. Mock return values can also be specified directly in git in your metadata.yaml

Changing mock return values

You can use mb.get_snowflake_mock_return_value to fetch mock return values for the current or previous versions of a deployment.

And you can use mb.set_snowflake_mock_return_value to change the mock value of a deployment without needing to call mb.deploy.

Using mock functionality with dbt

To use mock functionality in your dbt models with a helpful macro, view the documentation about calling your models from dbt.