How to debug into prodigy custom recipes?

Suppose we have a custom recipe like below:

@prodigy.recipe(
    "entity_linker.manual",
    dataset=("The dataset to use", "positional", None, str),
    source=("The source data as a .txt file", "positional", None, Path),
    nlp_dir=("Path to the NLP model with a pretrained NER component", "positional", None, Path),
    kb_loc=("Path to the KB", "positional", None, Path),
    entity_loc=("Path to the file with additional information about the entities", "positional", None, Path),
)
def entity_linker_manual(dataset, source, nlp_dir, kb_loc, entity_loc):
    # Load the NLP and KB objects from file
    nlp = spacy.load(nlp_dir)
    kb = KnowledgeBase(vocab=nlp.vocab, entity_vector_length=1)
    kb.load_bulk(kb_loc)
    model = EntityRecognizer(nlp)
..........................

How do we debug into the code?

Thanks!

Hi! What exactly do you mean by debugging here? Do you want to add tests to make sure your recipe runs as expected? Or do you just want to log what's going on at different points in the code?

Prodigy recipes are regular Python functions that return a dictionary of components. So you can test them in your test suite like you would test any other functions. You can also use the log helper to add custom messages to the debugging logs (or just print statements :sweat_smile:)

Can I set a breakpoint in the prodigy recipe file [ see screenshot] to debug?

You should be able to, yes – after all, it's just a basic Python function. Depending on how your editor's debugging tools work, you might have to run the recipe separately as a function to debug it. Or, if you run it via Prodigy's web server, you can also add print statements or your own custom logic that raises a system exit under certain conditions.