Skip to content

Reusing the runner's latest doesn't work as expected in input guardrails #804

@prophet1906

Description

@prophet1906

Please read this first

  • Have you read the docs? Yes
  • Have you searched for related issues? Yes

Describe the bug

Guardrail Execution Error example in the Exceptions section of the Running Agents guide doesn't work as expected.

Not sure if this is a bug or expected behavior, as there is a proper comment at

// Only run input guardrails on the first turn of a new run.
if (result.state._currentTurn === 1 && !isResumingFromInterruption) {

This behavior is also documented in the Guardrails guide as "Input guardrails run on the initial user input".

As per the comment, input guardrails only run on the first turn of a new run. So, I think the example is incorrect. I tend to do a fresh run using e.state._originalInput, but this isn't a good idea.

Suggestion - Rewriting the example to demonstrate the reuse of the runner's latest state with output guardrails is more realistic, as it is more common to have one input guardrail and multiple output guardrails in a single flow.

Debug information

  • Agents SDK version: (e.g. v0.0.1)
  • Runtime environment (e.g. Node.js 22.16.0)

Repro steps

Run the example present in the docs, the fallbackGuardrail is not triggered.

Expected behavior

We expect the fallbackGuardrail to be triggered and we should get the expected output present in docs.

Guardrail execution failed: Error: Input guardrail failed to complete: Error: Something is wrong!
Math homework guardrail tripped

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions