LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.
LangWatch provides a flexible system for capturing various types of evaluations and implementing guardrails within your LLM applications. This allows you to track performance, ensure quality, and control application flow based on defined criteria.There are three main ways to work with evaluations and guardrails:
Client-Side Custom Evaluations (add_evaluation): Log any custom evaluation metric, human feedback, or external system score directly from your Python code. These are primarily for observational purposes.
Server-Side Managed Evaluations (evaluate, async_evaluate): Trigger predefined or custom evaluation logic that runs on the LangWatch backend. These can return scores, pass/fail results, and other details.
Guardrails: A special application of evaluations (either client-side or server-side) used to make decisions or enforce policies within your application flow.
You can log custom evaluation data directly from your application code using the add_evaluation() method on a LangWatchSpan or LangWatchTrace object. This is useful for recording metrics specific to your domain, results from external systems, or human feedback.When you call add_evaluation(), LangWatch typically creates a new child span of type evaluation (or guardrail if is_guardrail=True) under the target span. This child span, named after your custom evaluation, stores its details, primarily in its output attribute.Here’s an example:
import langwatch# Assume langwatch.setup() has been called@langwatch.span(name="Generate Response")def process_request(user_query: str): response_text = f"Response to: {user_query}" langwatch.get_current_span().update(output=response_text) # Example 1: A simple pass/fail custom evaluation contains_keyword = "LangWatch" in response_text langwatch.get_current_span().add_evaluation( name="Keyword Check: LangWatch", passed=contains_keyword, details=f"Checked for 'LangWatch'. Found: {contains_keyword}" ) # Example 2: A custom score for response quality human_score = 4.5 langwatch.get_current_span().add_evaluation( name="Human Review: Quality Score", score=human_score, label="Good", details="Reviewed by Jane Doe. Response is clear and relevant." ) # Example 3: A client-side guardrail check is_safe = not ("unsafe_word" in response_text) langwatch.get_current_span().add_evaluation( name="Safety Check (Client-Side)", passed=is_safe, is_guardrail=True, # Mark this as a guardrail details=f"Content safety check. Passed: {is_safe}" ) if not is_safe: # Potentially alter flow or log a critical warning print("Warning: Client-side safety check failed!") return response_text@langwatch.trace(name="Process User Request")def main(): user_question = "Tell me about LangWatch." generated_response = process_request(user_question) print(f"Query: {user_question}") print(f"Response: {generated_response}")if __name__ == "__main__": main()
The add_evaluation() method is available on both LangWatchSpan and LangWatchTrace objects (when using on a trace, you must specify the target span). For detailed parameter descriptions, please refer to the API reference:
LangWatch allows you to trigger evaluations that are performed by the LangWatch backend. These can be built-in evaluators (e.g., for faithfulness, relevance) or custom evaluators you define in your LangWatch project settings.You use the evaluate() (synchronous) or async_evaluate() (asynchronous) functions for this. These functions send the necessary data to the LangWatch API, which then processes the evaluation. These server-side evaluations are a core part of setting up real-time monitoring and evaluations in production.
import langwatchfrom langwatch.evaluations import BasicEvaluateData# from langwatch.types import RAGChunk # For RAG contexts# Assume langwatch.setup() has been called@langwatch.span()def handle_rag_query(user_query: str): retrieved_contexts_str = [ "LangWatch helps monitor LLM applications.", "Evaluations can be run on the server." ] # For richer context, use RAGChunk # retrieved_contexts_rag = [ # RAGChunk(content="LangWatch helps monitor LLM applications.", document_id="doc1"), # RAGChunk(content="Evaluations can be run on the server.", document_id="doc2") # ] # Add the RAG contexts to the current span langwatch.get_current_span().update(contexts=retrieved_contexts_str) # Simulate LLM call llm_output = f"Based on the context, LangWatch is for monitoring and server-side evals." # Prepare data for server-side evaluation eval_data = BasicEvaluateData( input=user_query, output=llm_output, contexts=retrieved_contexts_str ) # Trigger a server-side "faithfulness" evaluation # The 'faithfulness-evaluator' slug must be configured in your LangWatch project try: faithfulness_result = langwatch.evaluate( slug="faithfulness-evaluator", # Slug of the evaluator in LangWatch name="Faithfulness Check (Server)", data=eval_data, ) print(f"Faithfulness Evaluation Result: {faithfulness_result}") # faithfulness_result is an EvaluationResultModel(status, passed, score, details, etc.) # Example: Using it as a guardrail if faithfulness_result.passed is False: print("Warning: Faithfulness check failed!") except Exception as e: print(f"Error during server-side evaluation: {e}") return llm_output@langwatch.trace()def main(): query = "What can LangWatch do with contexts?" response = handle_rag_query(query) print(f"Query: {query}") print(f"Response: {response}")if __name__ == "__main__": main()
The evaluate() and async_evaluate() methods are available on both LangWatchSpan and LangWatchTrace objects. They can also be imported from langwatch.evaluations and called as langwatch.evaluate() or langwatch.async_evaluate(), where you would then explicitly pass the span or trace argument. For detailed parameter descriptions, refer to the API reference:
Understanding the data Parameter:The core parameters like slug, data, settings, as_guardrail, span, and trace are generally consistent.
For the data parameter specifically: BasicEvaluateData gives input, output and contexts a standardized structure, which is what many built-in evaluators expect. But data can be any dictionary, so you can pass arbitrary structures tailored to the custom server-side evaluators you define.BasicEvaluateData with fields like expected_output is useful when evaluating if the LLM is generating the right answers against a set of expected outputs. Where a golden answer is not available, use an open-ended evaluation instead, such as LLM-as-a-judge.
The slug parameter refers to the unique identifier of the evaluator configured in your LangWatch project settings. You can find a list of available evaluator types and learn how to configure them in our LLM Evaluation documentation.The functions return an EvaluationResultModel containing status, passed, score, details, label, and cost.
Guardrails are evaluations used to make decisions or enforce policies within your application. They typically result in a boolean passed status that your code can act upon.Using Server-Side Evaluations as Guardrails:
Set as_guardrail=True when calling evaluate or async_evaluate.
import langwatch# ... (inside a function with a current span)eval_data = BasicEvaluateData(output=llm_response)pii_check_result = langwatch.evaluate( slug="pii-detection-guardrail", data=eval_data, as_guardrail=True, span=langwatch.get_current_span())if pii_check_result.passed is False: # Take action: sanitize response, return a canned message, etc. return "Response redacted due to PII."
as_guardrail=True changes what happens when the evaluation process itself fails, for example when the evaluator service is down. The result carries status="error" and passed defaults to True, so a broken guardrail does not break your application. That is a “pass by default on error” stance, which is the right one when the guardrail is advisory rather than a hard gate.For safety-focused real-time evaluations such as PII detection or prompt injection monitors, see Setting up Real-Time Evaluations.Using Client-Side add_evaluation as Guardrails:
Set is_guardrail=True when calling add_evaluation.
# ... (inside a function with a current span)is_too_long = len(llm_response) > 1000response_span.add_evaluation( name="Length Guardrail", passed=(not is_too_long), is_guardrail=True, details=f"Length: {len(llm_response)}. Max: 1000")if is_too_long: # Take action: truncate response, ask for shorter output, etc. return llm_response[:1000] + "..."
For client-side guardrails added with add_evaluation, your code is fully responsible for interpreting the passed status and handling any errors during the local check.
How Evaluations and Guardrails Appear in LangWatch
Both client-side and server-side evaluations (including those marked as guardrails) are logged as spans in LangWatch.
add_evaluation: Creates a child span of type evaluation (or guardrail if is_guardrail=True).
evaluate/async_evaluate: Also create a child span of type evaluation (or guardrail if as_guardrail=True).
These spans will contain the evaluation’s name, result (score, passed, label), details, cost, and any associated metadata, typically within their output attribute. This allows you to:
See a history of all evaluation outcomes.
Filter traces by evaluation results.
Analyze the performance of different evaluators or guardrails.
Correlate evaluation outcomes with other trace data (e.g., LLM inputs/outputs, latencies).
Client-Side: Log scores from a custom heuristic checking for politeness in responses.
Server-Side: Trigger a managed “Toxicity” evaluator on LLM outputs, or use more open-ended approaches like an LLM-as-a-judge for tasks without predefined correct answers.
Compliance & Safety:
Client-Side Guardrail: Perform a regex check for forbidden words and log it with is_guardrail=True.
Server-Side Guardrail: Use a managed “PII Detection” evaluator with as_guardrail=True to decide if a response can be shown.
Performance Monitoring:
Client-Side: Log human feedback scores (add_evaluation) for helpfulness.
A/B Testing: Log custom metrics or trigger standard evaluations for different model versions or prompts to compare their performance.
Feedback Integration: add_evaluation can be used to pipe scores from an external human review platform directly into the relevant trace.
Last modified on October 29, 2026
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"LangWatch","description":"LangWatch is an open-source LLMOps platform for observability, evaluations, prompt optimization, and agent testing.","colors":{"primary":"#e17100","light":"#fe9a00","dark":"#e17100"},"logo":{"light":"https://mintcdn.com/langwatch/RHmZel47SBF9eSZV/logo/dark.svg?fit=max\u0026auto=format\u0026n=RHmZel47SBF9eSZV\u0026q=85\u0026s=27fe16868ec581a9af33ced4398a0671","dark":"https://mintcdn.com/langwatch/RHmZel47SBF9eSZV/logo/light.svg?fit=max\u0026auto=format\u0026n=RHmZel47SBF9eSZV\u0026q=85\u0026s=08e9fbfe7cc5eff149cf77ee0809fe4f"},"favicon":"https://mintcdn.com/langwatch/AB8PLEfk80GQISzj/favicon.svg?fit=max\u0026auto=format\u0026n=AB8PLEfk80GQISzj\u0026q=85\u0026s=2f4e9559be1b98d8ad4afe23097bfbc3","api":{"playground":{"display":"interactive"},"examples":{"defaults":"required","languages":["python","typescript","curl"]}},"appearance":{"default":"system","strict":false},"navbar":{"links":[{"href":"https://docs.langwatch.ai/llms.txt","label":"llms.txt"},{"href":"https://app.langwatch.ai/?utm_source=docs\u0026utm_medium=docs\u0026utm_campaign=navbar-signin","label":"Sign In"}],"primary":{"type":"github","href":"https://github.com/langwatch/langwatch"}},"search":{"prompt":"Search the LangWatch docs"},"seo":{"organization":{"name":"LangWatch","url":"https://langwatch.ai","logo":"https://langwatch.ai/docs/logo/light.svg","sameAs":["https://github.com/langwatch/langwatch","https://x.com/langwatchai","https://www.linkedin.com/company/langwatch/","https://www.youtube.com/@LangWatch"]},"indexing":"navigable"},"integrations":{"gtm":{"tagId":"GTM-KJ4S6Z9C"}},"banner":{"content":"**[Get started with LangWatch Skills in seconds](https://langwatch.ai/docs/skills/directory):** Set up evals, scenario tests, and tracing just by asking your AI coding assistant.","dismissible":true},"errors":{"404":{"redirect":false,"title":"Page not found","description":"Most moved pages redirect on their own. If one of our own links sent you here, report it and we will fix it."}},"contextual":{"options":["copy","view","claude","chatgpt","cursor","vscode","mcp"],"display":"header"},"metadata":{"timestamp":true},"markdown":{"instructions":"If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details."},"styling":{"latex":true},"navigation":{"global":{"anchors":[{"anchor":"Get Support","icon":"life-ring","href":"https://docs.langwatch.ai/support#email-support"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"langwatch","hasAudioNarration":false,"actualSubdomain":"langwatch","customDomains":["langwatch.ai"],"gitSource":{"type":"github","owner":"langwatch","repo":"langwatch","deployBranch":"main","contentDirectory":"docs","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6aec7ec98029e5fb8e3e607a","collectionId":"e1cd5cc9-04d1-4cd2-bacb-78997b8375f7","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6aec7ec98029e5fb8e3e607a"},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6aee67965b2d9a50d6c3cf82","clientVersion":"0.0.4076","searchFilterCounts":[{"language":"default","tag":"API Reference","count":416},{"language":"default","tag":"Platform","count":139},{"language":"default","tag":"Observability","count":108},{"language":"default","tag":"AI Gateway","count":77},{"language":"default","tag":"Self Hosting","count":43},{"language":"default","tag":"Evaluations","count":38},{"language":"default","tag":"SDKs","count":38},{"language":"default","tag":"Built-in Evaluators","count":33},{"language":"default","tag":"AI Governance","count":30},{"language":"default","tag":"Coding Agents","count":28}]},"assistantConfig":{},"basePath":"/docs","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"comment-mode","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":".tabs .overflow-x-auto{overflow-x:visible!important}a[href=\"https://github.com/langwatch/langwatch\"] .text-sm{white-space:nowrap}[aria-controls~=\"accordion\"]{padding-right:8px;padding-left:8px;align-items:start}[aria-controls~=\"accordion\"] p:last-child{font-size:14px;margin-top:0.5rem}[aria-controls~=\"accordion\"] [class=\"mr-0.5\"]{margin-top:5px}[aria-controls~=\"accordion\"][aria-expanded=\"true\"] [class=\"mr-0.5\"]{margin-top:8px}#sidebar-group .lg\\:text-sm{font-size:0.85rem!important}#sidebar-group .lg\\:leading-6{line-height:1.375rem!important}#sidebar-group .mb-5{margin-bottom:0.75rem!important}#sidebar-group .sm\\:mb-4{margin-bottom:0.5rem!important}#sidebar-group .py-1\\.5{padding-top:0.25rem!important;padding-bottom:0.25rem!important}#sidebar-group .mt-12 .lg\\:mt-8{margin-top:2rem!important}#sidebar-group .mb-3\\.5{margin-bottom:0.5rem!important}#sidebar-group h5{font-size:0.9rem!important}#sidebar-group svg{height:0.8rem!important;width:0.8rem!important}#sidebar-group svg[viewBox=\"0 -9 3 24\"]{stroke-width:1px!important;height:28px!important;width:12px!important;opacity:0.8!important}#sidebar-group .group{position:relative!important;padding-right:20px!important}#sidebar-group .group svg[viewBox=\"0 -9 3 24\"]{position:absolute!important;right:8px!important;top:50%!important;transform:translateY(-50%)!important}#sidebar-group .duration-75{transform:none!important}#sidebar-group .group svg[viewBox=\"0 -9 3 24\"].duration-75{transform:translateY(-50%)!important}#sidebar-group .group svg[viewBox=\"0 -9 3 24\"].duration-75.rotate-90{transform:translateY(-50%) rotate(90deg)!important}.line-highlight{background:rgb(85 215 153 / 0.2)!important}.line-highlight:before{background:rgb(85 215 153 / 0.2)!important;border-left:4px solid rgb(85 215 153)!important}.line-highlight:after{background:rgb(85 215 153 / 0.2)!important}code{max-width:100%;overflow-x:auto}.lw-copy-prompt{border:1px solid #e5e7eb;border-radius:12px;padding:12px 16px;display:flex;align-items:center;justify-content:space-between;gap:12px;cursor:pointer;transition:all 0.15s;margin-bottom:8px}.lw-copy-prompt:hover{background:#f9fafb}.lw-copy-btn{display:flex;align-items:center;gap:6px;padding:6px 12px;border-radius:8px;border:1px solid #e5e7eb;background:transparent;cursor:pointer;font-size:13px;font-weight:500;transition:all 0.15s;white-space:nowrap;color:inherit}.lw-copy-btn .lw-check-icon{display:none}.lw-copy-btn .lw-copy-icon{display:flex;align-items:center;gap:6px}.lw-copy-btn[data-copied] .lw-copy-icon{display:none}.lw-copy-btn[data-copied] .lw-check-icon{display:flex;align-items:center;gap:6px}.lw-copy-btn[data-copied]{background:#ecfdf5;color:#059669;border-color:#059669}.lw-copy-prompt[data-copied] .lw-copy-line-icon{display:none!important}.lw-copy-prompt[data-copied] .lw-copy-line-check{display:flex!important}.dark .lw-copy-prompt{border-color:#374151}.dark .lw-copy-prompt:hover{background:transparent;border-color:#6b7280}.dark .lw-copy-prompt:hover span{color:#f9fafb}.dark .lw-copy-btn{border-color:#374151}.dark .lw-copy-prompt:hover .lw-copy-btn{border-color:#6b7280;color:#f9fafb}.dark .lw-copy-btn[data-copied]{background:rgba(5, 150, 105, 0.15);border-color:rgba(5, 150, 105, 0.4);color:#059669}.lw-skill-install{border:1px solid #e5e7eb;border-radius:12px;padding:20px 24px;margin-bottom:16px}.lw-skill-install.lw-skill-highlighted{border-color:rgba(225, 113, 0, 0.4);background:rgba(225, 113, 0, 0.06)}.dark .lw-skill-install{border-color:#374151}.dark .lw-skill-install.lw-skill-highlighted{border-color:rgba(225, 113, 0, 0.4)}.lw-inline-copy-btn{display:inline-flex;align-items:center;padding:2px;border:none;background:transparent;color:#9ca3af;cursor:pointer;transition:color 0.15s;vertical-align:middle}.lw-inline-copy-btn:hover{color:#6b7280}.dark .lw-inline-copy-btn:hover{color:#d1d5db}.lw-info-box{display:flex;gap:12px;padding:16px;border:1px solid #e5e7eb;border-radius:12px;background:#f9fafb;margin-bottom:16px;margin-top:32px}.lw-info-box-icon{flex-shrink:0;color:#6b7280;margin-top:6px}.lw-info-box-content{flex:1;min-width:0;font-size:14px}.lw-info-box-content p{margin:0 0 8px}.lw-info-box-content p:last-child{margin-bottom:0}.lw-info-box-content pre{margin:8px 0 0!important}.lw-info-box-content [data-component-part=\"code-block-root\"]{padding-top:6px!important}.lw-info-box-content .code-block{margin-bottom:0!important}.dark .lw-info-box{border-color:#374151;background:rgba(255, 255, 255, 0.03)}.dark .lw-info-box-icon{color:#9ca3af}.lw-accordion{border:1px solid #e5e7eb;border-radius:12px;margin-bottom:8px;overflow:hidden}.lw-accordion-header{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;cursor:pointer;transition:background 0.15s;list-style:none}.lw-accordion-header:hover{background:#f9fafb}.lw-accordion-title{font-size:14px}.lw-accordion-chevron{flex-shrink:0;transition:transform 0.2s;color:#9ca3af}.lw-accordion[data-open] .lw-accordion-chevron{transform:rotate(180deg)}.lw-accordion-body{display:none;padding:0 16px 16px;border-top:1px solid #e5e7eb}.lw-accordion[data-open] .lw-accordion-body{display:block}.lw-accordion-static .lw-accordion-header{cursor:default}.lw-accordion-static .lw-accordion-header:hover{background:transparent}.lw-prompt-source{display:none}.lw-accordion-commands{display:flex;gap:16px;margin-top:12px}.lw-accordion-cmd-col{flex:1;min-width:0}.lw-accordion-cmd-label{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:0.05em;color:#6b7280;margin-bottom:6px}.lw-accordion-cmd-box{display:flex;align-items:center;gap:8px;padding:8px 12px;background:#f9fafb;border-radius:8px;border:1px solid #e5e7eb;cursor:pointer;transition:border-color 0.15s}.lw-accordion-cmd-box:hover{border-color:#d1d5db}.lw-accordion-cmd-box code{font-size:13px;font-family:var(--font-mono, monospace);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:1;min-width:0;background:transparent!important;padding:0!important;border:none!important}.lw-slash-command{color:#e17100;font-weight:600}.lw-accordion-cmd-box[data-copied]{border-color:#059669;background:#ecfdf5}.lw-accordion-cmd-box[data-copied] .lw-copy-line-icon{display:none!important}.lw-accordion-cmd-box[data-copied] .lw-copy-line-check{display:inline-flex!important}.lw-accordion-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px}.lw-accordion-action{display:flex;align-items:center;gap:8px;padding:6px 12px 6px 6px;border:1px solid #e5e7eb;border-radius:8px;background:transparent;cursor:pointer;text-decoration:none;color:inherit;transition:all 0.15s;text-align:left}.lw-accordion-action:hover{background:#f9fafb;border-color:#d1d5db}.lw-accordion-action-icon{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid #e5e7eb;border-radius:6px;color:#6b7280;flex-shrink:0}.lw-accordion-action-text{display:flex;flex-direction:column;line-height:1.2}.lw-accordion-action-title{font-size:13px;font-weight:500}.lw-accordion-action-subtitle{font-size:11px;font-weight:400;color:#9ca3af}.lw-accordion-action[data-copied]{background:#ecfdf5;border-color:#059669}.lw-accordion-action[data-copied] .lw-copy-line-icon{display:none!important}.lw-accordion-action[data-copied] .lw-copy-line-check{display:flex!important}.dark .lw-accordion{border-color:#374151}.dark .lw-accordion-header:hover{background:rgba(255, 255, 255, 0.03)}.dark .lw-accordion-static .lw-accordion-header:hover{background:transparent}.dark .lw-accordion-body{border-top-color:#374151}.dark .lw-accordion-cmd-box{background:rgba(255, 255, 255, 0.05);border-color:#374151}.dark .lw-accordion-cmd-box:hover{border-color:#6b7280}.dark .lw-accordion-cmd-box[data-copied]{background:rgba(5, 150, 105, 0.15);border-color:rgba(5, 150, 105, 0.4)}.dark .lw-accordion-action{border-color:#374151}.dark .lw-accordion-action-icon{border-color:#374151}.dark .lw-accordion-action:hover{background:rgba(255, 255, 255, 0.03);border-color:#6b7280}.dark .lw-accordion-action[data-copied]{background:rgba(5, 150, 105, 0.15);border-color:rgba(5, 150, 105, 0.4)}.dark .lw-accordion-chevron{color:#6b7280}.dark .lw-slash-command{color:#fe9a00}#sidebar-group .group>img{align-self:center}#footer{flex-wrap:wrap;row-gap:0}.lw-agent-report{flex:0 0 100%;font-size:14px;color:#9ca3af;padding-bottom:12px}.lw-agent-report a{color:inherit;text-decoration:underline;text-underline-offset:2px}.lw-agent-report a:hover{color:#6b7280}.lw-agent-report code{font-size:13px;white-space:nowrap;background:rgba(0, 0, 0, 0.04);border:1px solid #e5e7eb;border-radius:4px;padding:1px 5px}.dark .lw-agent-report{color:#6b7280}.dark .lw-agent-report a:hover{color:#9ca3af}.dark .lw-agent-report code{background:rgba(255, 255, 255, 0.05);border-color:#374151}"}],"page":{"pagePath":"integration/python/tutorials/capturing-evaluations-guardrails","slug":"/integration/python/tutorials/capturing-evaluations-guardrails","pageMetadata":{"title":"Capturing Evaluations \u0026 Guardrails","sidebarTitle":"Evaluations \u0026 Guardrails","description":"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.","keywords":"Custom Evaluations, Managed Evaluations, Guardrails, LangWatch Evaluations, add_evaluation, evaluate, async_evaluate, Evaluation Metric, Evaluation Score, Evaluation Pass/Fail, Evaluation Label, Evaluation Details, Evaluation Cost, Evaluation Status, Evaluation Error, Evaluation Timestamps, Evaluation Type, Guardrail","href":"/integration/python/tutorials/capturing-evaluations-guardrails"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,em:`em`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Tip}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Tip)_missingMdxReference(`Tip`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`LangWatch provides a flexible system for capturing various types of evaluations and implementing guardrails within your LLM applications. This allows you to track performance, ensure quality, and control application flow based on defined criteria.`}),`\n`,_jsx(_components.p,{children:`There are three main ways to work with evaluations and guardrails:`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsxs(_components.strong,{children:[`Client-Side Custom Evaluations (`,_jsx(_components.code,{children:`add_evaluation`}),`)`]}),`: Log any custom evaluation metric, human feedback, or external system score directly from your Python code. These are primarily for observational purposes.`]}),`\n`,_jsxs(_components.li,{children:[_jsxs(_components.strong,{children:[`Server-Side Managed Evaluations (`,_jsx(_components.code,{children:`evaluate`}),`, `,_jsx(_components.code,{children:`async_evaluate`}),`)`]}),`: Trigger predefined or custom evaluation logic that runs on the LangWatch backend. These can return scores, pass/fail results, and other details.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Guardrails`}),`: A special application of evaluations (either client-side or server-side) used to make decisions or enforce policies within your application flow.`]}),`\n`]}),`\n`,_jsxs(Heading,{level:`2`,id:`1-client-side-custom-evaluations-add_evaluation`,children:[`1. Client-Side Custom Evaluations (`,_jsx(_components.code,{children:`add_evaluation`}),`)`]}),`\n`,_jsxs(_components.p,{children:[`You can log custom evaluation data directly from your application code using the `,_jsx(_components.code,{children:`add_evaluation()`}),` method on a `,_jsx(_components.code,{children:`LangWatchSpan`}),` or `,_jsx(_components.code,{children:`LangWatchTrace`}),` object. This is useful for recording metrics specific to your domain, results from external systems, or human feedback.`]}),`\n`,_jsxs(_components.p,{children:[`When you call `,_jsx(_components.code,{children:`add_evaluation()`}),`, LangWatch typically creates a new child span of type `,_jsx(_components.code,{children:`evaluation`}),` (or `,_jsx(_components.code,{children:`guardrail`}),` if `,_jsx(_components.code,{children:`is_guardrail=True`}),`) under the target span. This child span, named after your custom evaluation, stores its details, primarily in its `,_jsx(_components.code,{children:`output`}),` attribute.`]}),`\n`,_jsx(_components.p,{children:`Here’s an example:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`50`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`50`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Assume langwatch.setup() has been called`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@langwatch.span`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Generate Response\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` process_request`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`user_query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response_text `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Response to: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`user_query`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.get_current_span().update(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`output`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response_text)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Example 1: A simple pass/fail custom evaluation`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` contains_keyword `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"LangWatch\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response_text`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.get_current_span().add_evaluation(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Keyword Check: LangWatch\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` passed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`contains_keyword,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` details`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Checked for 'LangWatch'. Found: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`contains_keyword`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Example 2: A custom score for response quality`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` human_score `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 4.5`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.get_current_span().add_evaluation(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Human Review: Quality Score\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` score`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`human_score,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` label`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Good\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` details`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Reviewed by Jane Doe. Response is clear and relevant.\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Example 3: A client-side guardrail check`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_safe `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"unsafe_word\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response_text)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.get_current_span().add_evaluation(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Safety Check (Client-Side)\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` passed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`is_safe,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` is_guardrail`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Mark this as a guardrail`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` details`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Content safety check. Passed: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`is_safe`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_safe:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Potentially alter flow or log a critical warning`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Warning: Client-side safety check failed!\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response_text`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@langwatch.trace`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Process User Request\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` main`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` user_question `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Tell me about LangWatch.\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` generated_response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` process_request(user_question)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Query: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`user_question`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Response: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`generated_response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` __name__`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"__main__\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` main()`})}),`\n`]})})}),`\n`,_jsxs(Heading,{level:`3`,id:`add_evaluation-parameters`,children:[_jsx(_components.code,{children:`add_evaluation()`}),` Parameters`]}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`add_evaluation()`}),` method is available on both `,_jsx(_components.code,{children:`LangWatchSpan`}),` and `,_jsx(_components.code,{children:`LangWatchTrace`}),` objects (when using on a trace, you must specify the target `,_jsx(_components.code,{children:`span`}),`). For detailed parameter descriptions, please refer to the API reference:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/integration/python/reference#langwatchspan-object-methods`,children:_jsx(_components.code,{children:`LangWatchSpan.add_evaluation()`})})}),`\n`,_jsx(_components.li,{children:_jsx(_components.a,{href:`/integration/python/reference#langwatchtrace-object-methods`,children:_jsx(_components.code,{children:`LangWatchTrace.add_evaluation()`})})}),`\n`]}),`\n`,_jsxs(Heading,{level:`2`,id:`2-server-side-managed-evaluations-evaluate-\u0026-async_evaluate`,children:[`2. Server-Side Managed Evaluations (`,_jsx(_components.code,{children:`evaluate`}),` \u0026 `,_jsx(_components.code,{children:`async_evaluate`}),`)`]}),`\n`,_jsxs(_components.p,{children:[`LangWatch allows you to trigger evaluations that are performed by the LangWatch backend. These can be `,_jsx(_components.a,{href:`/evaluations/evaluators/list`,children:`built-in evaluators`}),` (e.g., for faithfulness, relevance) or `,_jsx(_components.a,{href:`/evaluations/evaluators/custom-scoring`,children:`custom evaluators you define`}),` in your LangWatch project settings.`]}),`\n`,_jsxs(_components.p,{children:[`You use the `,_jsx(_components.code,{children:`evaluate()`}),` (synchronous) or `,_jsx(_components.code,{children:`async_evaluate()`}),` (asynchronous) functions for this. These functions send the necessary data to the LangWatch API, which then processes the evaluation. These server-side evaluations are a core part of setting up `,_jsx(_components.a,{href:`/evaluations/online-evaluation/setup-monitors`,children:`real-time monitoring and evaluations in production`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`61`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`61`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.evaluations `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` BasicEvaluateData`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# from langwatch.types import RAGChunk # For RAG contexts`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Assume langwatch.setup() has been called`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@langwatch.span`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` handle_rag_query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`user_query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` retrieved_contexts_str `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"LangWatch helps monitor LLM applications.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Evaluations can be run on the server.\"`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # For richer context, use RAGChunk`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # retrieved_contexts_rag = [`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # RAGChunk(content=\"LangWatch helps monitor LLM applications.\", document_id=\"doc1\"),`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # RAGChunk(content=\"Evaluations can be run on the server.\", document_id=\"doc2\")`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # ]`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Add the RAG contexts to the current span`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.get_current_span().update(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`contexts`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`retrieved_contexts_str)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Simulate LLM call`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` llm_output `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Based on the context, LangWatch is for monitoring and server-side evals.\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Prepare data for server-side evaluation`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` eval_data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` BasicEvaluateData(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` input`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`user_query,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` output`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`llm_output,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` contexts`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`retrieved_contexts_str`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Trigger a server-side \"faithfulness\" evaluation`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # The 'faithfulness-evaluator' slug must be configured in your LangWatch project`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` faithfulness_result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.evaluate(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` slug`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"faithfulness-evaluator\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Slug of the evaluator in LangWatch`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Faithfulness Check (Server)\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`eval_data,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Faithfulness Evaluation Result: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`faithfulness_result`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # faithfulness_result is an EvaluationResultModel(status, passed, score, details, etc.)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Example: Using it as a guardrail`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` faithfulness_result.passed `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`is`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Warning: Faithfulness check failed!\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` except`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` Exception`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` e:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Error during server-side evaluation: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`e`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` llm_output`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@langwatch.trace`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` main`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`():`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` query `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"What can LangWatch do with contexts?\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` handle_rag_query(query)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Query: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`query`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Response: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` __name__`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"__main__\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` main()`})}),`\n`]})})}),`\n`,_jsxs(Heading,{level:`3`,id:`evaluate--async_evaluate-key-parameters`,children:[_jsx(_components.code,{children:`evaluate()`}),`, `,_jsx(_components.code,{children:`async_evaluate()`}),` Key Parameters`]}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`evaluate()`}),` and `,_jsx(_components.code,{children:`async_evaluate()`}),` methods are available on both `,_jsx(_components.code,{children:`LangWatchSpan`}),` and `,_jsx(_components.code,{children:`LangWatchTrace`}),` objects. They can also be imported from `,_jsx(_components.code,{children:`langwatch.evaluations`}),` and called as `,_jsx(_components.code,{children:`langwatch.evaluate()`}),` or `,_jsx(_components.code,{children:`langwatch.async_evaluate()`}),`, where you would then explicitly pass the `,_jsx(_components.code,{children:`span`}),` or `,_jsx(_components.code,{children:`trace`}),` argument. For detailed parameter descriptions, refer to the API reference:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/integration/python/reference#langwatchspan-object-methods`,children:_jsx(_components.code,{children:`LangWatchSpan.evaluate()`})}),` and `,_jsx(_components.a,{href:`/integration/python/reference#langwatchspan-object-methods`,children:_jsx(_components.code,{children:`LangWatchSpan.async_evaluate()`})})]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`/integration/python/reference#langwatchtrace-object-methods`,children:_jsx(_components.code,{children:`LangWatchTrace.evaluate()`})}),` and `,_jsx(_components.a,{href:`/integration/python/reference#langwatchtrace-object-methods`,children:_jsx(_components.code,{children:`LangWatchTrace.async_evaluate()`})})]}),`\n`]}),`\n`,_jsxs(Tip,{children:[_jsx(_components.p,{children:_jsxs(_components.strong,{children:[`Understanding the `,_jsx(_components.code,{children:`data`}),` Parameter:`]})}),_jsxs(_components.p,{children:[`The core parameters like `,_jsx(_components.code,{children:`slug`}),`, `,_jsx(_components.code,{children:`data`}),`, `,_jsx(_components.code,{children:`settings`}),`, `,_jsx(_components.code,{children:`as_guardrail`}),`, `,_jsx(_components.code,{children:`span`}),`, and `,_jsx(_components.code,{children:`trace`}),` are generally consistent.\nFor the `,_jsx(_components.code,{children:`data`}),` parameter specifically: `,_jsx(_components.code,{children:`BasicEvaluateData`}),` gives `,_jsx(_components.code,{children:`input`}),`, `,_jsx(_components.code,{children:`output`}),` and `,_jsx(_components.code,{children:`contexts`}),` a standardized structure, which is what many built-in evaluators expect. But `,_jsx(_components.code,{children:`data`}),` can be `,_jsx(_components.strong,{children:`any dictionary`}),`, so you can pass arbitrary structures tailored to the custom server-side evaluators you define.`]}),_jsxs(_components.p,{children:[_jsx(_components.code,{children:`BasicEvaluateData`}),` with fields like `,_jsx(_components.code,{children:`expected_output`}),` is useful when `,_jsx(_components.a,{href:`/evaluations/experiments/ui/answer-correctness`,children:`evaluating if the LLM is generating the right answers`}),` against a set of expected outputs. Where a golden answer is not available, use an open-ended evaluation instead, such as `,_jsx(_components.a,{href:`/evaluations/experiments/ui/llm-as-a-judge`,children:`LLM-as-a-judge`}),`.`]})]}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`slug`}),` parameter refers to the unique identifier of the evaluator configured in your LangWatch project settings. You can find a list of available evaluator types and learn how to configure them in our `,_jsx(_components.a,{href:`/evaluations/evaluators/list`,children:`LLM Evaluation documentation`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`The functions return an `,_jsx(_components.code,{children:`EvaluationResultModel`}),` containing `,_jsx(_components.code,{children:`status`}),`, `,_jsx(_components.code,{children:`passed`}),`, `,_jsx(_components.code,{children:`score`}),`, `,_jsx(_components.code,{children:`details`}),`, `,_jsx(_components.code,{children:`label`}),`, and `,_jsx(_components.code,{children:`cost`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`3-guardrails`,children:`3. Guardrails`}),`\n`,_jsxs(_components.p,{children:[`Guardrails are evaluations used to make decisions or enforce policies within your application. They typically result in a boolean `,_jsx(_components.code,{children:`passed`}),` status that your code can act upon.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Using Server-Side Evaluations as Guardrails:`}),`\nSet `,_jsx(_components.code,{children:`as_guardrail=True`}),` when calling `,_jsx(_components.code,{children:`evaluate`}),` or `,_jsx(_components.code,{children:`async_evaluate`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`14`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`14`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# ... (inside a function with a current span)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`eval_data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` BasicEvaluateData(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`output`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`llm_response)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`pii_check_result `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` langwatch.evaluate(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` slug`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"pii-detection-guardrail\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` data`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`eval_data,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` as_guardrail`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` span`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`langwatch.get_current_span()`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pii_check_result.passed `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`is`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Take action: sanitize response, return a canned message, etc.`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Response redacted due to PII.\"`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`as_guardrail=True`}),` changes what happens when the `,_jsx(_components.em,{children:`evaluation process itself`}),` fails, for example when the evaluator service is down. The result carries `,_jsx(_components.code,{children:`status=\"error\"`}),` and `,_jsx(_components.code,{children:`passed`}),` defaults to `,_jsx(_components.code,{children:`True`}),`, so a broken guardrail does not break your application. That is a “pass by default on error” stance, which is the right one when the guardrail is advisory rather than a hard gate.`]}),`\n`,_jsxs(_components.p,{children:[`For safety-focused real-time evaluations such as PII detection or prompt injection monitors, see `,_jsx(_components.a,{href:`/evaluations/online-evaluation/setup-monitors`,children:`Setting up Real-Time Evaluations`}),`.`]}),`\n`,_jsxs(_components.p,{children:[_jsxs(_components.strong,{children:[`Using Client-Side `,_jsx(_components.code,{children:`add_evaluation`}),` as Guardrails:`]}),`\nSet `,_jsx(_components.code,{children:`is_guardrail=True`}),` when calling `,_jsx(_components.code,{children:`add_evaluation`}),`.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# ... (inside a function with a current span)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`is_too_long `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(llm_response) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 1000`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response_span.add_evaluation(`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Length Guardrail\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` passed`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_too_long),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` is_guardrail`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` details`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Length: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`len`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(llm_response)`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`. Max: 1000\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` is_too_long:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Take action: truncate response, ask for shorter output, etc.`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` llm_response[:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1000`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`+`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"...\"`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`For client-side guardrails added with `,_jsx(_components.code,{children:`add_evaluation`}),`, your code is fully responsible for interpreting the `,_jsx(_components.code,{children:`passed`}),` status and handling any errors during the local check.`]}),`\n`,_jsx(Heading,{level:`2`,id:`how-evaluations-and-guardrails-appear-in-langwatch`,children:`How Evaluations and Guardrails Appear in LangWatch`}),`\n`,_jsx(_components.p,{children:`Both client-side and server-side evaluations (including those marked as guardrails) are logged as spans in LangWatch.`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`add_evaluation`}),`: Creates a child span of type `,_jsx(_components.code,{children:`evaluation`}),` (or `,_jsx(_components.code,{children:`guardrail`}),` if `,_jsx(_components.code,{children:`is_guardrail=True`}),`).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`evaluate`}),`/`,_jsx(_components.code,{children:`async_evaluate`}),`: Also create a child span of type `,_jsx(_components.code,{children:`evaluation`}),` (or `,_jsx(_components.code,{children:`guardrail`}),` if `,_jsx(_components.code,{children:`as_guardrail=True`}),`).`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`These spans will contain the evaluation’s name, result (score, passed, label), details, cost, and any associated metadata, typically within their `,_jsx(_components.code,{children:`output`}),` attribute. This allows you to:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`See a history of all evaluation outcomes.`}),`\n`,_jsx(_components.li,{children:`Filter traces by evaluation results.`}),`\n`,_jsx(_components.li,{children:`Analyze the performance of different evaluators or guardrails.`}),`\n`,_jsx(_components.li,{children:`Correlate evaluation outcomes with other trace data (e.g., LLM inputs/outputs, latencies).`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`use-cases`,children:`Use Cases`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Quality Assurance`}),`:`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Client-Side`}),`: Log scores from a custom heuristic checking for politeness in responses.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Server-Side`}),`: Trigger a managed `,_jsx(_components.a,{href:`/evaluations/evaluators/list`,children:`“Toxicity” evaluator`}),` on LLM outputs, or use more open-ended approaches like an `,_jsx(_components.a,{href:`/evaluations/experiments/ui/llm-as-a-judge`,children:`LLM-as-a-judge`}),` for tasks without predefined correct answers.`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Compliance \u0026 Safety`}),`:`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Client-Side Guardrail`}),`: Perform a regex check for forbidden words and log it with `,_jsx(_components.code,{children:`is_guardrail=True`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Server-Side Guardrail`}),`: Use a managed `,_jsx(_components.a,{href:`/evaluations/evaluators/list`,children:`“PII Detection” evaluator`}),` with `,_jsx(_components.code,{children:`as_guardrail=True`}),` to decide if a response can be shown.`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Performance Monitoring`}),`:`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Client-Side`}),`: Log human feedback scores (`,_jsx(_components.code,{children:`add_evaluation`}),`) for helpfulness.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Server-Side`}),`: Evaluate RAG system outputs for `,_jsx(_components.a,{href:`/evaluations/evaluators/list`,children:`“Context Relevancy” and “Faithfulness”`}),` using managed evaluators.`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`A/B Testing`}),`: Log custom metrics or trigger standard evaluations for different model versions or prompts to compare their performance.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Feedback Integration`}),`: `,_jsx(_components.code,{children:`add_evaluation`}),` can be used to pipe scores from an external human review platform directly into the relevant trace.`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Capturing Evaluations \u0026 Guardrails","sidebarTitle":"Evaluations \u0026 Guardrails","description":"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.","keywords":"Custom Evaluations, Managed Evaluations, Guardrails, LangWatch Evaluations, add_evaluation, evaluate, async_evaluate, Evaluation Metric, Evaluation Score, Evaluation Pass/Fail, Evaluation Label, Evaluation Details, Evaluation Cost, Evaluation Status, Evaluation Error, Evaluation Timestamps, Evaluation Type, Guardrail","href":"/integration/python/tutorials/capturing-evaluations-guardrails"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"1. Client-Side Custom Evaluations (add_evaluation)","slug":"1-client-side-custom-evaluations-add_evaluation","depth":2,"children":[{"title":"add_evaluation() Parameters","slug":"add_evaluation-parameters","depth":3,"children":[]}]},{"title":"2. Server-Side Managed Evaluations (evaluate \u0026 async_evaluate)","slug":"2-server-side-managed-evaluations-evaluate-\u0026-async_evaluate","depth":2,"children":[{"title":"evaluate(), async_evaluate() Key Parameters","slug":"evaluate--async_evaluate-key-parameters","depth":3,"children":[]}]},{"title":"3. Guardrails","slug":"3-guardrails","depth":2,"children":[]},{"title":"How Evaluations and Guardrails Appear in LangWatch","slug":"how-evaluations-and-guardrails-appear-in-langwatch","depth":2,"children":[]},{"title":"Use Cases","slug":"use-cases","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/docs/_mintlify/custom/langwatch/1c7dbbb4aa0b0c87/expand-menus.js","/docs/_mintlify/custom/langwatch/fdd2d1ee81d630a0/posthog.js"],"subdomain":"langwatch","siteName":"LangWatch","title":"Capturing Evaluations \u0026 Guardrails - LangWatch","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-10-29T01:41:33.308Z","gitLastModified":"2026-10-29T01:40:40.000Z","originalFileLocation":"integration/python/tutorials/capturing-evaluations-guardrails.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.\">\u003cmeta data-mint-head name=\"application-name\" content=\"LangWatch\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Capturing Evaluations \u0026amp; Guardrails - LangWatch\">\u003cmeta data-mint-head property=\"og:description\" content=\"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"LangWatch\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://langwatch.mintlify.site/docs/_mintlify/api/og/v2?division=Evaluations+%26+Guardrails\u0026amp;title=Capturing+Evaluations+%26+Guardrails\u0026amp;description=LangWatch+logs+custom+evaluations%2C+triggers+managed+evaluations%2C+and+runs+guardrails.\u0026amp;theme=c82022416a7a1873b973b6a4\u0026amp;signature=e2b6199cf427e9667ce8415493e5ff835172d61b1bea9bf122147740cd8cd2aa\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Capturing Evaluations \u0026amp; Guardrails - LangWatch\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://langwatch.mintlify.site/docs/_mintlify/api/og/v2?division=Evaluations+%26+Guardrails\u0026amp;title=Capturing+Evaluations+%26+Guardrails\u0026amp;description=LangWatch+logs+custom+evaluations%2C+triggers+managed+evaluations%2C+and+runs+guardrails.\u0026amp;theme=c82022416a7a1873b973b6a4\u0026amp;signature=e2b6199cf427e9667ce8415493e5ff835172d61b1bea9bf122147740cd8cd2aa\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/docs/mintlify-assets/_mintlify/favicons/langwatch/kXoUUhFGtPYqSZK4/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"LangWatch\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#e17100\">\u003clink data-mint-head rel=\"canonical\" href=\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/integration/python/tutorials/capturing-evaluations-guardrails.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://langwatch.ai/#organization\",\"name\":\"LangWatch\",\"url\":\"https://langwatch.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://langwatch.ai/docs/logo/light.svg\"},\"sameAs\":[\"https://github.com/langwatch/langwatch\",\"https://x.com/langwatchai\",\"https://www.linkedin.com/company/langwatch/\",\"https://www.youtube.com/@LangWatch\"]},{\"@type\":\"WebSite\",\"@id\":\"https://langwatch.ai/docs#website\",\"name\":\"LangWatch\",\"url\":\"https://langwatch.ai/docs\",\"publisher\":{\"@id\":\"https://langwatch.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails#webpage\",\"url\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails\",\"name\":\"Capturing Evaluations \u0026 Guardrails\",\"description\":\"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.\",\"dateModified\":\"2026-10-29T01:40:40.000Z\",\"isPartOf\":{\"@id\":\"https://langwatch.ai/docs#website\"},\"breadcrumb\":{\"@id\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SDKs\",\"item\":\"https://langwatch.ai/docs/integration/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-mapping-input-output\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Capturing Evaluations \u0026 Guardrails\",\"item\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails#article\",\"headline\":\"Capturing Evaluations \u0026 Guardrails\",\"name\":\"Capturing Evaluations \u0026 Guardrails\",\"description\":\"LangWatch logs custom evaluations, triggers managed evaluations, and runs guardrails.\",\"url\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails\",\"mainEntityOfPage\":{\"@id\":\"https://langwatch.ai/docs/integration/python/tutorials/capturing-evaluations-guardrails#webpage\"},\"dateModified\":\"2026-10-29T01:40:40.000Z\",\"publisher\":{\"@id\":\"https://langwatch.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://langwatch.ai/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"LangWatch\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"LangWatch","nav":{"global":{"anchors":[{"anchor":"Get Support","icon":"life-ring","href":"https://docs.langwatch.ai/support#email-support"}]},"anchors":[{"anchor":"Platform","icon":"book-open","pages":[{"title":"Platform","href":"/introduction"}]},{"anchor":"Observability","icon":"plug","groups":[{"group":"Overview","pages":[{"title":"Getting Started","href":"/integration/overview"},{"title":"Choosing the right OTel endpoint","sidebarTitle":"Trace vs governance ingestion","href":"/observability/trace-vs-activity-ingestion"}]},{"group":"SDKs","root":{"title":"Getting Started","href":"/integration/overview"},"expanded":true,"pages":[{"group":"Python","icon":"python","pages":[{"title":"Python Integration Guide","sidebarTitle":"Guide","href":"/integration/python/guide"},{"title":"Python SDK API Reference","sidebarTitle":"Reference","icon":"terminal","href":"/integration/python/reference"},{"title":"Python Connected Agent Reference","sidebarTitle":"Agent reference","icon":"terminal","href":"/integration/python/agent-reference"},{"title":"Manual Instrumentation","href":"/integration/python/tutorials/manual-instrumentation"},{"title":"OpenTelemetry Migration","href":"/integration/python/tutorials/open-telemetry"}]},{"group":"TypeScript","icon":"typescript","pages":[{"title":"TypeScript Integration Guide","sidebarTitle":"Guide","href":"/integration/typescript/guide"},{"title":"TypeScript SDK API Reference","sidebarTitle":"Reference","icon":"terminal","href":"/integration/typescript/reference"},{"title":"TypeScript Connected Agent Reference","sidebarTitle":"Agent reference","icon":"terminal","href":"/integration/typescript/agent-reference"},{"title":"Filtering Spans in TypeScript","sidebarTitle":"Filtering Spans","icon":"filter","href":"/integration/typescript/tutorials/filtering-spans"},{"title":"Manual Instrumentation","sidebarTitle":"Manual Control","href":"/integration/typescript/tutorials/manual-instrumentation"},{"title":"OpenTelemetry Migration","href":"/integration/typescript/tutorials/opentelemetry-migration"},{"title":"Debugging and Troubleshooting","sidebarTitle":"Debugging","href":"/integration/typescript/tutorials/debugging-typescript"},{"title":"Semantic Conventions","sidebarTitle":"Semantic Conventions","href":"/integration/typescript/tutorials/semantic-conventions"}]},{"group":"Go SDK","icon":"/images/logos/golang.svg","pages":[{"title":"Go Integration Guide","sidebarTitle":"Guide","href":"/integration/go/guide"},{"title":"Go SDK API Reference","sidebarTitle":"Reference","icon":"terminal","href":"/integration/go/reference"}]},{"title":"Metadata and Labels","sidebarTitle":"Metadata \u0026 Labels","icon":"tags","href":"/integration/metadata-and-labels"},{"group":"Tutorials","pages":[{"group":"Capturing Input/Output","pages":[{"title":"Capturing and Mapping Inputs \u0026 Outputs","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/capturing-mapping-input-output"},{"title":"Capturing and Mapping Inputs \u0026 Outputs","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/capturing-input-output"}]},{"group":"Capturing RAG","pages":[{"title":"Capturing RAG","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/capturing-rag"},{"title":"Capturing RAG","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/capturing-rag"}]},{"group":"Capturing Metadata","pages":[{"title":"Capturing Metadata and Attributes","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/capturing-metadata"},{"title":"Capturing Metadata and Attributes","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/capturing-metadata"}]},{"group":"Capturing Images","pages":[{"title":"Capturing Images","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/capturing-images"},{"title":"Capturing Images","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/capturing-images"}]},{"group":"Capturing Documents","pages":[{"title":"Capturing Documents","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/capturing-documents"},{"title":"Capturing Documents","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/capturing-documents"}]},{"group":"Capturing Audio and Voice","pages":[{"title":"Capturing Audio and Voice","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/capturing-audio"},{"title":"Capturing Audio and Voice","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/capturing-audio"}]},{"group":"Tracking LLM Costs","pages":[{"title":"Tracking LLM Costs and Tokens","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/tracking-llm-costs"},{"title":"Tracking LLM Costs and Tokens","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/tracking-llm-costs"}]},{"group":"Tracking Time to First Token","pages":[{"title":"Tracking Time to First Token (TTFT)","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/tracking-time-to-first-token"},{"title":"Tracking Time to First Token (TTFT)","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/tracking-time-to-first-token"}]},{"group":"Tracking Tool Calls","pages":[{"title":"Tracking Tool Calls","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/tracking-tool-calls"},{"title":"Tracking Tool Calls","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/tutorials/tracking-tool-calls"}]},{"group":"Tracking Conversations","pages":[{"title":"Tracking Conversations","sidebarTitle":"Python","icon":"python","href":"/integration/python/tutorials/tracking-conversations"},{"title":"Tracking Conversations","sidebarTitle":"TypeScript/JS","description":"Group related traces into conversations using thread_id so you can view and evaluate entire chat sessions in LangWatch.","icon":"square-js","href":"/integration/typescript/tutorials/tracking-conversations"}]},{"group":"Evaluations \u0026 Guardrails","pages":[{"title":"Capturing Evaluations \u0026 Guardrails","sidebarTitle":"Evaluations \u0026 Guardrails","href":"/integration/python/tutorials/capturing-evaluations-guardrails"}]},{"title":"Combining the SDK with OpenTelemetry Spans","description":"LangWatch receives traces from an existing OpenTelemetry setup in Python and TypeScript.","href":"/integration/tutorials/open-telemetry"}]}]},{"group":"Frameworks","root":{"title":"Getting Started","href":"/integration/overview"},"expanded":true,"pages":[{"group":"LangChain","expanded":true,"pages":[{"title":"LangChain Instrumentation","sidebarTitle":"Python","icon":"python","href":"/integration/python/integrations/langchain"},{"title":"LangChain Instrumentation","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/integrations/langchain"}]},{"group":"LangGraph","expanded":true,"pages":[{"title":"LangGraph Instrumentation","sidebarTitle":"LangGraph","icon":"python","href":"/integration/python/integrations/langgraph"},{"title":"LangGraph Instrumentation","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/integrations/langgraph"}]},{"title":"Vercel AI SDK","sidebarTitle":"Vercel AI SDK","href":"/integration/typescript/integrations/vercel-ai-sdk"},{"title":"OpenAI Agents SDK Instrumentation","sidebarTitle":"OpenAI Agents","href":"/integration/python/integrations/open-ai-agents"},{"title":"PydanticAI Instrumentation","sidebarTitle":"PydanticAI","href":"/integration/python/integrations/pydantic-ai"},{"title":"Mastra","sidebarTitle":"Mastra","href":"/integration/typescript/integrations/mastra"},{"title":"DSPy Instrumentation","sidebarTitle":"DSPy","href":"/integration/python/integrations/dspy"},{"group":"DSPy Optimization","pages":[{"title":"DSPy Visualization Quickstart","sidebarTitle":"Quickstart","href":"/dspy-visualization/quickstart"},{"title":"Tracking Custom DSPy Optimizer","sidebarTitle":"Custom Optimizer Tracking","href":"/dspy-visualization/custom-optimizer"},{"title":"RAG Visualization","href":"/dspy-visualization/rag-visualization"}]},{"title":"LlamaIndex Instrumentation","sidebarTitle":"LlamaIndex","href":"/integration/python/integrations/llamaindex"},{"title":"Haystack Instrumentation","sidebarTitle":"Haystack","href":"/integration/python/integrations/haystack"},{"title":"Strands Agents Instrumentation","sidebarTitle":"Strands Agents","href":"/integration/python/integrations/strand-agents"},{"title":"Agno Instrumentation","sidebarTitle":"Agno","href":"/integration/python/integrations/agno"},{"title":"CrewAI","href":"/integration/python/integrations/crew-ai"},{"title":"AutoGen Instrumentation","sidebarTitle":"AutoGen","href":"/integration/python/integrations/autogen"},{"title":"Semantic Kernel Instrumentation","sidebarTitle":"Semantic Kernel","href":"/integration/python/integrations/semantic-kernel"},{"title":"Spring AI (Java) Integration","sidebarTitle":"Spring AI","href":"/integration/java/integrations/spring-ai"},{"title":"PromptFlow Instrumentation","sidebarTitle":"PromptFlow","href":"/integration/python/integrations/promptflow"},{"title":"Instructor AI Instrumentation","sidebarTitle":"Instructor AI","href":"/integration/python/integrations/instructor"},{"title":"SmolAgents Instrumentation","sidebarTitle":"SmolAgents","href":"/integration/python/integrations/smolagents"},{"title":"Google Agent Development Kit (ADK) Instrumentation","sidebarTitle":"Google ADK","href":"/integration/python/integrations/google-ai"},{"title":"Firebase Genkit Integration","sidebarTitle":"Genkit","href":"/integration/go/integrations/genkit"},{"title":"Other OpenTelemetry Instrumentors","sidebarTitle":"Other","href":"/integration/python/integrations/other"}]},{"group":"Model Providers","root":{"title":"Getting Started","href":"/integration/overview"},"expanded":true,"pages":[{"title":"Custom Models","sidebarTitle":"Custom Models","href":"/integration/custom-models"},{"group":"OpenAI","expanded":true,"pages":[{"title":"OpenAI Instrumentation","sidebarTitle":"Python","icon":"python","href":"/integration/python/integrations/open-ai"},{"title":"OpenAI","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/integrations/open-ai"},{"title":"OpenAI Instrumentation","sidebarTitle":"Go SDK","icon":"golang","href":"/integration/go/integrations/open-ai"}]},{"group":"Anthropic (Claude)","expanded":true,"pages":[{"title":"Claude Platform (Claude API OpenTelemetry)","sidebarTitle":"Claude Platform","icon":"cloud","href":"/integration/anthropic/claude-platform"},{"title":"Anthropic Instrumentation","sidebarTitle":"Python","icon":"python","href":"/integration/python/integrations/anthropic"},{"title":"Anthropic (Claude) Integration","sidebarTitle":"Go SDK","icon":"golang","href":"/integration/go/integrations/anthropic"}]},{"group":"Microsoft Azure","expanded":true,"pages":[{"title":"Azure AI Inference SDK Instrumentation","sidebarTitle":"Python","icon":"python","href":"/integration/python/integrations/azure-ai"},{"title":"Azure OpenAI Instrumentation","sidebarTitle":"Azure OpenAI","href":"/integration/python/integrations/open-ai-azure"},{"title":"Azure OpenAI","sidebarTitle":"TypeScript/JS","icon":"square-js","href":"/integration/typescript/integrations/azure"},{"title":"Azure OpenAI Integration","sidebarTitle":"Go SDK","icon":"golang","href":"/integration/go/integrations/azure-openai"}]},{"group":"Google Cloud","expanded":true,"pages":[{"title":"Google Vertex AI Instrumentation","sidebarTitle":"Vertex AI","icon":"python","href":"/integration/python/integrations/vertex-ai"},{"title":"Google Gemini Integration","sidebarTitle":"Go SDK","icon":"golang","href":"/integration/go/integrations/google-gemini"}]},{"group":"Amazon Web Services","expanded":true,"pages":[{"title":"AWS Bedrock Instrumentation","sidebarTitle":"Bedrock","icon":"python","href":"/integration/python/integrations/aws-bedrock"},{"title":"Amazon Bedrock Integration","sidebarTitle":"Go SDK","icon":"golang","href":"/integration/go/integrations/amazon-bedrock"}]},{"title":"Groq Integration","sidebarTitle":"Groq","href":"/integration/go/integrations/groq"},{"title":"Grok (xAI) Integration","sidebarTitle":"Grok (xAI)","href":"/integration/go/integrations/grok"},{"title":"Ollama (Local Models) Integration","sidebarTitle":"Ollama (Local)","href":"/integration/go/integrations/ollama"},{"group":"OpenRouter","pages":[{"title":"OpenRouter Broadcast Integration","sidebarTitle":"OpenRouter Broadcast","href":"/integration/openrouter-broadcast"},{"title":"OpenRouter Integration","sidebarTitle":"OpenRouter","href":"/integration/go/integrations/openrouter"}]},{"group":"LiteLLM","expanded":true,"pages":[{"title":"LiteLLM Proxy Integration","sidebarTitle":"LiteLLM Proxy","href":"/integration/litellm-proxy"},{"title":"LiteLLM Instrumentation","sidebarTitle":"LiteLLM","href":"/integration/python/integrations/lite-llm"}]}]},{"group":"Tools","expanded":true,"pages":[{"title":"OpenClaw Integration","sidebarTitle":"OpenClaw","href":"/integration/openclaw"}]},{"group":"No-Code Platforms","root":{"title":"Getting Started","href":"/integration/overview"},"expanded":true,"pages":[{"title":"LangWatch + n8n Integration","sidebarTitle":"n8n","href":"/integration/n8n"},{"title":"Langflow Integration","sidebarTitle":"Langflow","href":"/integration/langflow"},{"title":"Flowise Integration","sidebarTitle":"Flowise","href":"/integration/flowise"}]},{"group":"Direct Integrations","root":{"title":"Getting Started","href":"/integration/overview"},"expanded":true,"pages":[{"title":"OpenTelemetry Integration Guide","sidebarTitle":"OpenTelemetry","icon":"telescope","href":"/integration/opentelemetry/guide"},{"title":"Running LangWatch with Other OTel SDKs","sidebarTitle":"Multiple OTel Providers","icon":"layer-group","href":"/integration/opentelemetry/multiple-providers"},{"title":"REST API","sidebarTitle":"HTTP API","icon":"globe","href":"/integration/rest-api"}]}]},{"anchor":"AI Gateway","icon":"route","pages":[{"title":"AI Gateway","href":"/ai-gateway/overview"}]},{"anchor":"AI Governance","icon":"shield-check","pages":[{"title":"AI Governance","href":"/ai-governance/overview"}]},{"anchor":"Coding Agents","icon":"square-terminal","pages":[{"title":"Coding Agents","href":"/coding-agents/overview"}]},{"anchor":"Langy","icon":"robot","pages":[{"title":"Langy","href":"/langy/overview"}]},{"anchor":"Self Hosting","icon":"server","pages":[{"title":"Self Hosting","href":"/self-hosting/overview"}]},{"anchor":"API Reference","icon":"code","pages":[{"title":"API Reference","href":"/api-reference/introduction"}]}]},"basePath":"","title":"Capturing Evaluations \u0026 Guardrails - LangWatch","buildId":"dpl_ATnXPMW25DMPUr9VBw6kL6MfBt6T","deploymentId":"dpl_ATnXPMW25DMPUr9VBw6kL6MfBt6T","dynamics":["10e4515597"],"chunks":["BannerMarkdown-B5WzX-8C.js","dist-BPypQKlo.js","lib-DuNMoZ05.js","lib-B8HbPgcC.js","clsx-6wHzaN2_.js","html-void-elements-mCSPHezU.js","katex-YMM-FMeD.js","marked.esm-CZWythHk.js"]}