Skip to content

Conversation

@TasmeerJamali
Copy link

Summary

Add comprehensive documentation for tool input and output guardrails to docs/guardrails.md. This addresses the gap identified in #1830 where tool guardrails (implemented in PR #1792) were not documented in the main guides.

The new documentation explains:

  • The difference between agent-level and tool-level guardrails
  • How to use @tool_input_guardrail and @tool_output_guardrail decorators
  • The three behavior types: allow, reject_content, and raise_exception
  • How to attach guardrails to tools and handle exceptions

Test plan

  • Verified documentation builds successfully with uv run mkdocs build
  • All code examples use valid Python syntax with correct imports
  • Formatting is consistent with existing documentation style

Issue number

Closes #1830

Checks

  • I've added new tests (if relevant) - N/A (documentation only)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

Add comprehensive documentation for tool input and output guardrails:
- Explain difference between tool and agent-level guardrails
- Document @tool_input_guardrail decorator with examples
- Document @tool_output_guardrail decorator with examples
- Add behavior types table (allow, reject_content, raise_exception)
- Include exception handling examples

Closes openai#1830
@seratch seratch added the documentation Improvements or additions to documentation label Dec 22, 2025
@seratch seratch added this to the 0.7.x milestone Dec 22, 2025
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this improvement! The changes look good to me, but as mentioned in my comments, I'd like to make the dev experience more intuitive before publishing these document sections. I will update you once the feature enhancement is available.



# Attach the guardrail to the tool
send_email.tool_input_guardrails = [validate_email_args]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this is the only way to pass tool guardrails but thinking of better developer experience, enabling to pass the same to the decorator would be better. I will come up with a pull request enhancing this.



# Attach the guardrail to the tool
get_user_data.tool_output_guardrails = [block_sensitive_data]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: add #1792 tool guardrails to the guardrails document page

2 participants