<@ULVA73B9P> I have registered my custom notificat...
# ask-marvin
s
@Marvin I have registered my custom notification block type on our prefect server instance. It is definitely there and can be used. But when I want to use it in an automation I still get the error that the slug of the block type can‘t be found. What is going wrong? Is it even possible to use custom block types in automations that are supposed to send notifications?
m
thought for 492.8 seconds
Short answer: Yes, you can use custom notification blocks in Prefect 3.x automations on Prefect Server. The “slug not found” error almost always means the API service that executes the automation cannot import your block class at runtime, so the registry lookup by slug fails. What’s happening - Automations (including Send notification) run inside the API service (your Prefect Server), not in your worker environment. - When an automation runs, Prefect loads the block document, reads its block type slug from the schema, then tries to resolve the Python class for that slug. - If the API process cannot import your block package (or your package isn’t registered as a Prefect collection), you’ll see an “UnknownBlockType / slug can’t be found” error even if the block type and block document exist in the database. Checklist to fix 1) Install your block package in the API environment - If you’re running Prefect Server in a container/VM, install your package there (the same environment where the API service runs). - If you registered the block from your laptop, that only wrote block types to the DB; it didn’t make your code available to the server. 2) Register it as a Prefect collection so Prefect auto-loads it - In your package’s pyproject.toml, expose an entry point under prefect.collections so the server can discover and import it:
Copy code
[project.entry-points."prefect.collections"]
my_company = "my_company_prefect"
- Ensure that importing my_company_prefect imports the module(s) that define your blocks. 3) Make sure your block declares the notification capability - Either inherit NotificationBlock or set the capability and implement notify:
Copy code
from prefect.blocks.core import Block

class MyNotifier(Block):
    _block_type_name = "My Notifier"
    _block_type_slug = "my-notifier"  # stabilize the slug
    _block_schema_capabilities = ["notify"]

    async def notify(self, body: str, subject: str | None = None) -> None:
        ...
4) Register/update block types in the server environment - After installing the package on the server:
Copy code
prefect block register -m my_company_prefect
5) Restart the API service - Entry points are loaded once per process; restart to ensure your collection is discovered. 6) Verify from the server environment - Check that the type is present in the API:
Copy code
prefect block type ls
prefect block type inspect my-notifier
- Optionally, sanity check class resolution:
Copy code
python -c "from prefect.blocks.core import Block; Block.get_block_class_from_key('my-notifier'); print('OK')"
Common gotchas - Entry points group name must be prefect.collections (not prefect.blocks). - If you renamed the class, your slug may have changed. Either set _block_type_slug explicitly or recreate/update your block documents so they reference the current slug. - If your block does not expose the “notify” capability, the automation will fail later with “not a notification block” even if the slug resolves. Notes about Cloud vs Server - You’re on Prefect Server, so installing your custom package into the API environment is supported and required. - For Prefect Cloud, the control plane cannot import your private packages; you generally cannot use custom notification blocks in automations there. Use built-in blocks or route through a webhook if you need custom behavior. If you can share: - The exact error text - How/where the custom package is installed - The slug you expect - How you registered the block (module/file) …I can help pinpoint the exact step that’s failing.