Skip to content

Ensure that input_guardrails can block tools from running - #931

Closed
rm-openai wants to merge 1 commit into
mainfrom
rm/pr931
Closed

Ensure that input_guardrails can block tools from running#931
rm-openai wants to merge 1 commit into
mainfrom
rm/pr931

Conversation

@rm-openai

@rm-openai rm-openai commented Jun 24, 2025

Copy link
Copy Markdown
Collaborator

Resolves #889

@seratch seratch added bug Something isn't working enhancement New feature or request feature:core labels Jun 25, 2025
@github-actions

github-actions Bot commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 10 days with no activity.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions Bot closed this Jul 13, 2025
@seratch seratch reopened this Aug 11, 2025
@seratch seratch added skip-stale and removed stale labels Aug 11, 2025
@seratch

seratch commented Aug 11, 2025

Copy link
Copy Markdown
Member

@rm-openai do you think this approach is still good to go? If not, we may want to think of a solution for #889 and #991

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions Bot added the stale label Aug 25, 2025
@lionelchg

lionelchg commented Aug 29, 2025

Copy link
Copy Markdown

Hi @seratch, just checked out on the PR and tried the following script (a shorter version of the quickstart script) - it still does not block the call.

  • this is the script:
from agents import Agent, InputGuardrail, GuardrailFunctionOutput, Runner
from agents.exceptions import InputGuardrailTripwireTriggered
from pydantic import BaseModel
import asyncio

class HomeworkOutput(BaseModel):
    is_homework: bool
    reasoning: str

guardrail_agent = Agent(
    name="Guardrail check",
    instructions="Check if the user is asking about homework.",
    output_type=HomeworkOutput,
)

math_tutor_agent = Agent(
    name="Math Tutor",
    handoff_description="Specialist agent for math questions",
    instructions="You provide help with math problems. Explain your reasoning at each step and include examples",
)

async def homework_guardrail(ctx, agent, input_data):
    result = await Runner.run(guardrail_agent, input_data, context=ctx.context)
    final_output = result.final_output_as(HomeworkOutput)
    return GuardrailFunctionOutput(
        output_info=final_output,
        tripwire_triggered=not final_output.is_homework,
    )

triage_agent = Agent(
    name="Triage Agent",
    instructions="You determine which agent to use based on the user's homework question",
    handoffs=[math_tutor_agent],
    input_guardrails=[
        InputGuardrail(guardrail_function=homework_guardrail),
    ],
)

async def main():
    # Example: General/philosophical question
    try:
        result = await Runner.run(triage_agent, "What is the meaning of life?")
        print(result.final_output)
    except InputGuardrailTripwireTriggered as e:
        print("Guardrail blocked this input:", e)

if __name__ == "__main__":
    asyncio.run(main())
  • this is my screenshot of the logs (you can see that the second call passes even though is_homework is False):
Screenshot 2025-08-30 at 01 01 04

I might try a fix this week-end will keep you posted!

@github-actions

github-actions Bot commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions Bot added the stale label Sep 9, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions Bot closed this Sep 17, 2025
@illia-botscrew

Copy link
Copy Markdown

@rm-openai do you plan to finish this support of blocking tools from running when input_guardrail is processing the input?

This PR and the other PR that was trying to add support for this: #1622 are closed.

@seratch
seratch deleted the rm/pr931 branch January 6, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request feature:core skip-stale stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileSearchTool runs despite InputGuardrailTripwireTriggered

4 participants