langchain-ai/deepagents · error · TypeError

Expected UserPromptSubmitDecision, got {type(decision).__nam

Error message

Expected UserPromptSubmitDecision, got {type(decision).__name__}

What it means

ClientHookService.user_prompt_submit validates that the decision object returned by the client-side hook handler is an instance of UserPromptSubmitDecision. If a registered hook callable returns anything else (a plain dict, None, a string, or a wrong Decision type), the service refuses to propagate it and raises TypeError. This guards the typed Hooks v2 contract so downstream agent logic can rely on a well-formed decision.

Source

Thrown at libs/code/deepagents_code/hooks/client_lifecycle.py:219

        Returns:
            Aggregated prompt decision.

        Raises:
            TypeError: If the runtime returns a mismatched decision type.
        """
        if not self.has_handlers(HookEvent.USER_PROMPT_SUBMIT):
            return UserPromptSubmitDecision(event=HookEvent.USER_PROMPT_SUBMIT)
        decision = await self._invoke(
            context,
            UserPromptSubmitEvent(
                event=HookEvent.USER_PROMPT_SUBMIT,
                prompt=prompt,
            ),
        )
        if not isinstance(decision, UserPromptSubmitDecision):
            msg = f"Expected UserPromptSubmitDecision, got {type(decision).__name__}"
            raise TypeError(msg)
        return decision

    async def pre_compact(
        self,
        context: ClientHookContext,
        trigger: CompactTrigger,
        *,
        custom_instructions: str = "",
    ) -> PreCompactDecision:
        """Invoke `PreCompact` through the session hook runtime.

        Args:
            context: Current client turn context.
            trigger: Manual or automatic compaction source.
            custom_instructions: Optional compaction instructions.

        Returns:
            Aggregated pre-compaction decision.

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Return a UserPromptSubmitDecision instance from the hook (e.g. UserPromptSubmitDecision.allow() or .block(reason=...)) instead of a dict or None
  2. If the hook returns raw data, validate/convert it with the library's pydantic adapter (e.g. UserPromptSubmitDecision.model_validate(raw)) before returning
  3. Check that the callback registered for USER_PROMPT_SUBMIT is not a generic handler reused from another event
  4. Update custom hook wrappers to the current typed Hooks v2 API if upgrading from an older version

Example fix

// before
def my_hook(context, event):
    return {"behavior": "allow"}

// after
from deepagents_code.hooks import UserPromptSubmitDecision

def my_hook(context, event):
    return UserPromptSubmitDecision.allow()
Defensive patterns

Strategy: type-guard

Validate before calling

from deepagents_code.hooks import UserPromptSubmitDecision

result = my_hook(context, event)
if not isinstance(result, UserPromptSubmitDecision):
    result = UserPromptSubmitDecision.model_validate(result)

Type guard

def is_user_prompt_decision(value: object) -> bool:
    return isinstance(value, UserPromptSubmitDecision)

Try / catch

try:
    decision = await service.user_prompt_submit(context, prompt)
except TypeError as exc:
    logger.warning("hook returned invalid decision: %s", exc)
    decision = UserPromptSubmitDecision.allow()

Prevention

When it happens

Trigger: Calling user_prompt_submit() (or on_user_prompt on the manager) when a registered USER_PROMPT_SUBMIT hook returns a non-UserPromptSubmitDecision value — e.g. returning {'behavior': 'allow'} dict instead of UserPromptSubmitDecision.allow(), returning None, or returning a Decision type from a different hook event.

Common situations: Hand-written hook callbacks written before the typed Decision classes existed; hooks shared across events where one callback returns the wrong decision type; deserializing decisions from JSON without running them through the pydantic adapter; typos like returning UserPromptSubmitDecision for a different event's decision class.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/f8192a596fd56f43. Report an issue: GitHub.