verify_io

verta.registry.verify_io(f)

Decorator to typecheck I/O to ensure platform compatibility when deployed.

Allowed input 1 and output 2 types are validated by Python’s standard json library.

Examples

import numpy as np
from verta.registry import verify_io, VertaModelBase

class MyModel(VertaModelBase):
    def __init__(self, artifacts=None):
        pass

    @verify_io
    def predict(self, input):
        return [x**2 for x in input]

model = MyModel()

# succeeds; a list will be given to the deployed model as-is
model.predict([1, 2, 3])

# fails; deployed model won't be able to receieve a NumPy array
model.predict(np.array([1, 2, 3]))

References

1

https://docs.python.org/3/library/json.html#json-to-py-table

2

https://docs.python.org/3/library/json.html#py-to-json-table

Notes

json.dumps() is used for its significantly faster performance compared to a manual recursive type-check, but there are a couple of edge cases where it will permit false negatives: most notably it will allow tuples which are actually passed as lists, though their interfaces are similar enough that misuse is unlikely.