from crewai.tasks.hallucination_guardrail import HallucinationGuardrailfrom crewai import LLM# Basic usage - will use task's expected_output as contextguardrail = HallucinationGuardrail( llm=LLM(model="gpt-4o-mini"))# With explicit reference contextcontext_guardrail = HallucinationGuardrail( context="AI helps with various tasks including analysis and generation.", llm=LLM(model="gpt-4o-mini"))
from crewai import Task# Create your task with the guardrailtask = Task( description="Write a summary about AI capabilities", expected_output="A factual summary based on the provided context", agent=my_agent, guardrail=guardrail # Add the guardrail to validate output)
# Guardrail with tool response contextweather_guardrail = HallucinationGuardrail( context="Current weather information for the requested location", llm=LLM(model="gpt-4o-mini"), tool_response="Weather API returned: Temperature 22°C, Humidity 65%, Clear skies")
# Example of guardrail result structure{ "valid": False, "feedback": "Content appears to be hallucinated (score: 4.2/10, verdict: HALLUCINATED). The output contains information not supported by the provided context."}
context = """Company XYZ was founded in 2020 and specializes in renewable energy solutions.They have 150 employees and generated $50M revenue in 2023.Their main products include solar panels and wind turbines."""
2
관련 있는 컨텍스트만 유지하기
혼란을 피하기 위해 작업과 직접적으로 관련된 정보만 포함하세요:
Copy
Ask AI
# Good: Focused contextcontext = "The current weather in New York is 18°C with light rain."# Avoid: Unrelated informationcontext = "The weather is 18°C. The city has 8 million people. Traffic is heavy."