Skip to content

Commit

Permalink
rail_parser: Extract validated output from Guardrails 0.3.0 return value
Browse files Browse the repository at this point in the history
  • Loading branch information
irgolic committed Dec 13, 2023
1 parent d826774 commit 1989142
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions libs/langchain/langchain/output_parsers/rail_parser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from typing import Any, Callable, Dict, Optional, TYPE_CHECKING
import importlib.metadata
import warnings
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional

from langchain_core.output_parsers import BaseOutputParser


if TYPE_CHECKING:
from guardrails.guard import Guard

Expand Down Expand Up @@ -149,4 +149,11 @@ def get_format_instructions(self) -> str:
return self.guard.raw_prompt.format_instructions

def parse(self, text: str) -> Dict:
return self.guard.parse(text, llm_api=self.api, *self.args, **self.kwargs)
result = self.guard.parse(text, llm_api=self.api, *self.args, **self.kwargs)

guardrails_version = importlib.metadata.version("guardrails-ai")
if guardrails_version >= "0.3.0":
# unpack validation outcome object
result = result.validated_output

return result

0 comments on commit 1989142

Please sign in to comment.