-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat: Add Cleanlab's AI Reliability Bundle to Langflow #8049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
91e13d8
b28232e
85e8a48
d7dcef5
94a1811
c663c1f
46cba3d
f3b0d27
bb00e92
7ee4227
b35acd3
89fabc4
b815be2
3faa101
a07b248
d6f331f
906a087
27bd34b
4c9132d
e056815
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| --- | ||
| title: Integrate Cleanlab Evaluations with Langflow | ||
| slug: /integrations-cleanlab | ||
| --- | ||
|
|
||
| Unlock trustworthy Agentic, RAG, and LLM pipelines with Cleanlab's evaluation and remediation suite. | ||
|
|
||
| [Cleanlab](https://www.cleanlab.ai/) adds automation and trust to every data point going in and every prediction coming out of AI and RAG solutions. | ||
|
|
||
| This Langflow integration provides 3 modular components that assess and improve the **trustworthiness** of any LLM or RAG pipeline output, enabling critical oversight for safety-sensitive, enterprise, and production GenAI applications. | ||
|
|
||
| Use this bundle to: | ||
| - Quantify trustworthiness of ANY LLM response with a **0-1 score** | ||
| - Explain why a response may be good or bad | ||
| - Evaluate **context sufficiency**, **groundedness**, **helpfulness**, and **query clarity** with quantitative scores (for RAG/Agentic pipelines with context) | ||
| - Remediate low-trust responses with warnings or fallback answers | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Before using these components, you'll need: | ||
|
|
||
| - A [Cleanlab API key](https://tlm.cleanlab.ai/) | ||
|
|
||
|
|
||
| ## Components | ||
|
|
||
| ### `CleanlabEvaluator` | ||
|
|
||
| **Purpose:** Evaluate and explain the trustworthiness of a prompt + response pair using Cleanlab. More details on how the score works [here](https://help.cleanlab.ai/tlm/). | ||
|
|
||
| #### Inputs | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------------|------------|---------------------------------------------------------------------| | ||
| | system_prompt | Message | (Optional) System message prepended to the prompt | | ||
| | prompt | Message | The user-facing input to the LLM | | ||
| | response | Message | OpenAI's, Claude, etc. model's response to evaluate | | ||
| | cleanlab_api_key | Secret | Your Cleanlab API key | | ||
| | cleanlab_evaluation_model | Dropdown | Evaluation model used by Cleanlab (GPT-4, Claude, etc.) This does not need to be the same model that generated the response. | | ||
| | quality_preset | Dropdown | Tradeoff between evaluation speed and accuracy | | ||
|
|
||
| #### Outputs | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------------|------------|---------------------------------------------------------------------| | ||
| | score | number | Trust score between 0–1 | | ||
| | explanation | Message | Explanation of the trust score | | ||
| | response | Message | Returns the original response for easy chaining to `CleanlabRemediator` component | | ||
|
|
||
| --- | ||
|
|
||
| ### `CleanlabRemediator` | ||
|
|
||
| **Purpose:** Use the trust score from the `CleanlabEvaluator` component to determine whether to show, warn about, or replace an LLM response. This component has configurables for the score threshold, warning text, and fallback message which you can customize as needed. | ||
|
|
||
| #### Inputs | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------------------|------------|-----------------------------------------------------------------------------| | ||
| | response | Message | The response to potentially remediate | | ||
| | score | number | Trust score from `CleanlabEvaluator` | | ||
| | explanation | Message | (Optional) Explanation to append if warning is shown | | ||
| | threshold | float | Minimum trust score to pass response unchanged | | ||
| | show_untrustworthy_response| bool | Show original response with warning if untrustworthy | | ||
| | untrustworthy_warning_text | Prompt | Warning text for untrustworthy responses | | ||
| | fallback_text | Prompt | Fallback message if response is hidden | | ||
|
|
||
| #### Output | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------------|------------|-----------------------------------------------------------------------------| | ||
| | remediated_response | Message | Final message shown to user after remediation logic | | ||
|
|
||
|
|
||
| See example outputs below! | ||
|
|
||
| --- | ||
|
|
||
| ### `CleanlabRAGEvaluator` | ||
|
|
||
| **Purpose:** Comprehensively evaluate RAG and LLM pipeline outputs by analyzing the context, query, and response quality using Cleanlab. This component assesses trustworthiness, context sufficiency, response groundedness, helpfulness, and query ease. Learn more about Cleanlab's evaluation metrics [here](https://help.cleanlab.ai/tlm/use-cases/tlm_rag/). You can also use the `CleanlabRemediator` component with this one to remediate low-trust responses coming from the RAG pipeline. | ||
|
|
||
| #### Inputs | ||
|
|
||
| | Name | Type | Description | | ||
| |--------------------------|-----------|----------------------------------------------------------------------------| | ||
| | cleanlab_api_key | Secret | Your Cleanlab API key | | ||
| | cleanlab_evaluation_model | Dropdown | Evaluation model used by Cleanlab (GPT-4, Claude, etc.) This does not need to be the same model that generated the response. | | ||
| | quality_preset | Dropdown | Tradeoff between evaluation speed and accuracy | | ||
| | context | Message | Retrieved context from your RAG system | | ||
| | query | Message | The original user query | | ||
| | response | Message | OpenAI's, Claude, etc. model's response based on the context and query | | ||
| | run_context_sufficiency | bool | Evaluate whether context supports answering the query | | ||
| | run_response_groundedness| bool | Evaluate whether the response is grounded in the context | | ||
| | run_response_helpfulness | bool | Evaluate how helpful the response is | | ||
| | run_query_ease | bool | Evaluate if the query is vague, complex, or adversarial | | ||
|
|
||
| #### Outputs | ||
|
|
||
| | Name | Type | Description | | ||
| |-----------------------|------------|-----------------------------------------------------------------------------| | ||
| | trust_score | number | Overall trust score | | ||
| | trust_explanation | Message | Explanation for trust score | | ||
| | other_scores | dict | Dictionary of optional enabled RAG evaluation metrics | | ||
| | evaluation_summary | Message | Markdown summary of query, context, response, and evaluation results | | ||
|
|
||
| --- | ||
|
|
||
| ## Example Flows | ||
|
|
||
| The following example flows show how to use the `CleanlabEvaluator` and `CleanlabRemediator` components to evaluate and remediate responses from any LLM, and how to use the `CleanlabRAGEvaluator` component to evaluate RAG pipeline outputs. | ||
|
|
||
| ### Evaluate and remediate responses from any LLM | ||
|
|
||
| [Download](./eval_and_remediate_cleanlab.json) the flow to follow along! | ||
|
|
||
| This flow evaluates and remediates the trustworthiness of a response from any LLM using the `CleanlabEvaluator` and `CleanlabRemediator` components. | ||
|
|
||
|  | ||
|
|
||
| Simply connect the `Message` output from any LLM component (like OpenAI, Anthropic, or Google) to the `response` input of the `CleanlabEvaluator` component, along with connecting your prompt to its `prompt` input. | ||
|
|
||
| That's it! The `CleanlabEvaluator` component will return a trust score and explanation which you can use however you'd like. | ||
|
|
||
| The `CleanlabRemediator` component uses this trust score and user configurable settings to determine whether to output the original response, warn about it, or replace it with a fallback answer. | ||
|
|
||
| The example below shows a response that was determined to be untrustworthy (score of .09) and flagged with a warning by the `CleanlabRemediator` component. | ||
|
|
||
|  | ||
|
|
||
| If you don't want to show untrustworthy responses, you can also configure the `CleanlabRemediator` to replace the response with a fallback message. | ||
|
|
||
|  | ||
|
|
||
| ### Evaluate RAG pipeline | ||
|
|
||
| The below flow is the `Vector Store RAG` example template, with the `CleanlabRAGEvaluator` component added to evaluate the context, query, and response. You can use the `CleanlabRAGEvaluator` with any flow that has a context, query, and response. Simply connect the `context`, `query`, and `response` outputs from any RAG pipeline to the `CleanlabRAGEvaluator` component. | ||
|
|
||
|  | ||
|
|
||
| Here is an example of the `Evaluation Summary` output from the `CleanlabRAGEvaluator` component. | ||
|
|
||
|  | ||
|
|
||
| Notice how the `Evaluation Summary` includes the query, context, response, and all the evaluation results! In this example, the `Context Sufficiency` and `Response Groundedness` scores are low (0.002) because the context doesn't contain information about the query and the response is not grounded in the context. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from .cleanlab_evaluator import CleanlabEvaluator | ||
| from .cleanlab_rag_evaluator import CleanlabRAGEvaluator | ||
| from .cleanlab_remediator import CleanlabRemediator | ||
|
|
||
| __all__ = ["CleanlabEvaluator", "CleanlabRAGEvaluator", "CleanlabRemediator"] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,145 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from cleanlab_tlm import TLM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from langflow.custom import Component | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from langflow.io import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownInput, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MessageTextInput, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Output, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SecretStrInput, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from langflow.schema.message import Message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class CleanlabEvaluator(Component): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """A component that evaluates the trustworthiness of LLM responses using Cleanlab. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This component takes a prompt and response pair, along with optional system instructions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and uses Cleanlab's evaluation algorithms to generate a trust score and explanation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Inputs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - system_prompt (MessageTextInput): Optional system-level instructions prepended to the user prompt. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - prompt (MessageTextInput): The user's prompt or query sent to the LLM. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - response (MessageTextInput): The response generated by the LLM to be evaluated. This should come from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LLM component, i.e. OpenAI, Gemini, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - api_key (SecretStrInput): Your Cleanlab API key. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - model (DropdownInput): The model used by Cleanlab to evaluate the response (can differ from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| generation model). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - quality_preset (DropdownInput): Tradeoff setting for accuracy vs. speed and cost. Higher presets are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slower but more accurate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Outputs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - response_passthrough (Message): The original response, passed through for downstream use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - score (number): A float between 0 and 1 indicating Cleanlab's trustworthiness score for the response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - explanation (Message): A textual explanation of why the response received its score. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This component works well in conjunction with the CleanlabRemediator to create a complete trust evaluation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and remediation pipeline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| More details on the evaluation metrics can be found here: https://help.cleanlab.ai/tlm/tutorials/tlm/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name = "Cleanlab Evaluator" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description = "Evaluates any LLM response using Cleanlab and outputs trust score and explanation." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon = "Cleanlab" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name = "CleanlabEvaluator" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputs = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MessageTextInput( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="system_prompt", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name="System Message", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info="System-level instructions prepended to the user query.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value="", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MessageTextInput( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="prompt", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name="Prompt", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info="The user's query to the model.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MessageTextInput( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="response", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name="Response", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info="The response to the user's query.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SecretStrInput( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="api_key", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name="Cleanlab API Key", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info="Your Cleanlab API key.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownInput( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="model", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name="Cleanlab Evaluation Model", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options=[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-4.1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-4.1-mini", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-4.1-nano", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "o4-mini", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "o3", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-4.5-preview", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-4o-mini", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-4o", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "o3-mini", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "o1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "o1-mini", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "gpt-3.5-turbo-16k", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "claude-3.7-sonnet", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "claude-3.5-sonnet-v2", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "claude-3.5-sonnet", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "claude-3.5-haiku", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "claude-3-haiku", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "nova-micro", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "nova-lite", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "nova-pro", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info="The model Cleanlab uses to evaluate the response. This does NOT need to be the same model that " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "generated the response.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value="gpt-4o-mini", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| advanced=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DropdownInput( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name="quality_preset", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_name="Quality Preset", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options=["base", "low", "medium", "high", "best"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value="medium", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info="This determines the accuracy, latency, and cost of the evaluation. Higher quality is generally " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "slower but more accurate.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| advanced=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputs = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Output(display_name="Response", name="response_passthrough", method="pass_response", types=["Message"]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Output(display_name="Trust Score", name="score", method="get_score", types=["number"]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Output(display_name="Explanation", name="explanation", method="get_explanation", types=["Message"]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _evaluate_once(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not hasattr(self, "_cached_result"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| full_prompt = f"{self.system_prompt}\n\n{self.prompt}" if self.system_prompt else self.prompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tlm = TLM( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api_key=self.api_key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options={"log": ["explanation"], "model": self.model}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| quality_preset=self.quality_preset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._cached_result = tlm.get_trustworthiness_score(full_prompt, self.response) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return self._cached_result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+121
to
+130
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for Cleanlab API calls. The Apply this diff to add proper error handling: def _evaluate_once(self):
if not hasattr(self, "_cached_result"):
- full_prompt = f"{self.system_prompt}\n\n{self.prompt}" if self.system_prompt else self.prompt
- tlm = TLM(
- api_key=self.api_key,
- options={"log": ["explanation"], "model": self.model},
- quality_preset=self.quality_preset,
- )
- self._cached_result = tlm.get_trustworthiness_score(full_prompt, self.response)
+ try:
+ full_prompt = f"{self.system_prompt}\n\n{self.prompt}" if self.system_prompt else self.prompt
+ tlm = TLM(
+ api_key=self.api_key,
+ options={"log": ["explanation"], "model": self.model},
+ quality_preset=self.quality_preset,
+ )
+ self._cached_result = tlm.get_trustworthiness_score(full_prompt, self.response)
+ except Exception as e:
+ self.status = f"Evaluation failed: {e!s}"
+ self._cached_result = {"trustworthiness_score": 0.0, "log": {"explanation": "Evaluation failed due to API error."}}
return self._cached_result📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_score(self) -> float: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = self._evaluate_once() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| score = result.get("trustworthiness_score", 0.0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.status = f"Trust score: {score:.2f}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return score | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_explanation(self) -> Message: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = self._evaluate_once() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| explanation = result.get("log", {}).get("explanation", "No explanation returned.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Message(text=explanation) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def pass_response(self) -> Message: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.status = "Passing through response." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Message(text=self.response) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Consider model list maintenance strategy.
The hardcoded model list includes many options, but some models like "gpt-4.1", "gpt-4.5-preview", and "o3" may not exist or could become outdated. Consider implementing a dynamic model list or adding documentation about model availability.
🌐 Web query:
💡 Result:
Current Available Models for Cleanlab TLM API (2024)
Cleanlab’s Trustworthy Language Model (TLM) API allows users to choose from a range of underlying large language models (LLMs), balancing accuracy, cost, and speed. As of 2024, the API supports the following models:
Notes:
Access & Configuration:
Summary
Cleanlab TLM API (2024) supports a diverse selection of the latest GPT, Claude, O-series, and Nova models, with flexibility for both high-accuracy and low-cost/latency applications. It remains extensible for enterprise needs, including support for custom and future public LLMs via trustworthiness scoring[5][7][8].
Citations:
Document and Future-Proof Cleanlab TLM Model List
The hardcoded model list in
src/backend/base/langflow/components/cleanlab/cleanlab_evaluator.py(lines 70–92) currently matches the Cleanlab TLM API offerings for 2024. To ensure this list stays up-to-date as new models are added or Beta models graduate, consider one of the following:Pinpointed locations:
src/backend/base/langflow/components/cleanlab/cleanlab_evaluator.py, lines 70–92By moving toward a configuration-driven or API-driven approach, you’ll reduce the maintenance burden and avoid hardcoding deprecated or newly released model names.
🤖 Prompt for AI Agents