AI / Core OpenAI Codex Application Fundamentals Interview Questions
What are guardrails in the context of OpenAI application development?
Guardrails are safety and quality validation layers that intercept, evaluate, and potentially modify or block inputs and outputs at various points in an LLM application pipeline. They are especially critical in agentic systems where the model may take actions with real-world consequences.
| Type | Where applied | What it does |
|---|---|---|
| Input guardrails | Before model call | Validate, sanitise, or reject user inputs |
| Output guardrails | After model response | Validate, reformat, or block model outputs |
| Semantic guardrails | Both | Check meaning and intent, not just syntax |
| Action guardrails | Before tool execution | Require approval for high-risk agent actions |
| Agents SDK guardrails | SDK layer | Declarative guardrails run automatically on agent I/O |
from agents import Agent, Runner, GuardrailFunctionOutput, InputGuardrail from pydantic import BaseModel # Define a guardrail that validates math homework requests class HomeworkCheck(BaseModel): is_homework_question: bool reasoning: str guardrail_agent = Agent( name="HomeworkGuardrail", instructions="Check if the user is asking for homework help.", output_type=HomeworkCheck, ) async def homework_guardrail(ctx, agent, input): result = await Runner.run(guardrail_agent, input, context=ctx.context) if result.final_output.is_homework_question: raise GuardrailFunctionOutput( output_info=result.final_output, tripwire_triggered=True, # block the request ) return GuardrailFunctionOutput(output_info=result.final_output) # Attach guardrail to the main agent: main_agent = Agent( name="TutorAgent", instructions="Help students learn programming concepts.", input_guardrails=[InputGuardrail(guardrail_function=homework_guardrail)], ) # For irreversible agent actions - require human approval: def confirm_database_write(action_description: str) -> bool: print(f"Agent wants to: {action_description}") return input("Approve? (y/n): ").lower() == "y"
In the Agents SDK, guardrails run in parallel with the agent's primary model call for minimum added latency. They use a fast, cheap model to evaluate the input, raising a tripwire_triggered flag to halt execution if a policy violation is detected.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
