UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

203 lines (197 loc) 7.71 kB
/** * Guardrails Node - Version 2 * Safeguard AI models from malicious input or prevent them from generating undesirable responses */ export interface LcGuardrailsV2Params { operation?: 'classify' | 'sanitize'; text: string | Expression<string> | PlaceholderValue; guardrails?: { /** This guardrail checks if specified keywords appear in the input text and can be configured to trigger tripwires based on keyword matches. Multiple keywords can be added separated by comma. * @displayOptions.show { /operation: ["classify"] } */ keywords?: string | Expression<string> | PlaceholderValue; /** Detects attempts to jailbreak or bypass AI safety measures * @displayOptions.show { /operation: ["classify"] } * @default {"value":{"threshold":0.7}} */ jailbreak?: { /** Value */ value?: { /** Minimum confidence threshold to trigger the guardrail (0.0 to 1.0) * @hint Inputs scoring less than this will be treated as violations */ threshold?: number | Expression<number>; /** Customize Prompt * @default false */ customizePrompt?: boolean | Expression<boolean>; /** The system prompt used by the guardrail. Thresholds and JSON output are enforced by the node automatically. * @displayOptions.show { customizePrompt: [true] } */ prompt?: string | Expression<string> | PlaceholderValue; }; }; /** Detects attempts to generate NSFW content * @displayOptions.show { /operation: ["classify"] } * @default {"value":{"threshold":0.7}} */ nsfw?: { /** Value */ value?: { /** Minimum confidence threshold to trigger the guardrail (0.0 to 1.0) * @hint Inputs scoring less than this will be treated as violations */ threshold?: number | Expression<number>; /** Customize Prompt * @default false */ customizePrompt?: boolean | Expression<boolean>; /** The system prompt used by the guardrail. Thresholds and JSON output are enforced by the node automatically. * @displayOptions.show { customizePrompt: [true] } */ prompt?: string | Expression<string> | PlaceholderValue; }; }; /** Detects attempts to use personal data content * @default {"value":{"type":"all"}} */ pii?: { /** Value */ value?: { /** Type */ type?: 'all' | 'selected' | Expression<string>; /** Entities * @displayOptions.show { type: ["selected"] } * @default [] */ entities?: Array<'CREDIT_CARD' | 'CRYPTO' | 'DATE_TIME' | 'EMAIL_ADDRESS' | 'IBAN_CODE' | 'IP_ADDRESS' | 'LOCATION' | 'PHONE_NUMBER' | 'MEDICAL_LICENSE' | 'US_BANK_NUMBER' | 'US_DRIVER_LICENSE' | 'US_ITIN' | 'US_PASSPORT' | 'US_SSN' | 'UK_NHS' | 'UK_NINO' | 'ES_NIF' | 'ES_NIE' | 'IT_FISCAL_CODE' | 'IT_DRIVER_LICENSE' | 'IT_VAT_CODE' | 'IT_PASSPORT' | 'IT_IDENTITY_CARD' | 'PL_PESEL' | 'SG_NRIC_FIN' | 'SG_UEN' | 'AU_ABN' | 'AU_ACN' | 'AU_TFN' | 'AU_MEDICARE' | 'IN_PAN' | 'IN_AADHAAR' | 'IN_VEHICLE_REGISTRATION' | 'IN_VOTER' | 'IN_PASSPORT' | 'FI_PERSONAL_IDENTITY_CODE'>; }; }; /** Detects attempts to use secret keys in the input text. Scans text for common patterns, applies entropy analysis to detect random-looking strings. * @default {"value":{"permissiveness":"balanced"}} */ secretKeys?: { /** Value */ value?: { /** Permissiveness */ permissiveness?: 'strict' | 'balanced' | 'permissive' | Expression<string>; }; }; /** Detects attempts to stray from the business scope * @displayOptions.show { /operation: ["classify"] } * @default {"value":{"threshold":0.7}} */ topicalAlignment?: { /** Value */ value?: { /** Minimum confidence threshold to trigger the guardrail (0.0 to 1.0) * @hint Inputs scoring less than this will be treated as violations */ threshold?: number | Expression<number>; /** The system prompt used by the guardrail. Thresholds and JSON output are enforced by the node automatically. * @hint Make sure you replace the placeholder. */ prompt?: string | Expression<string> | PlaceholderValue; }; }; /** Blocks URLs that are not in the allowed list * @default {"value":{"allowedSchemes":["https"],"allowedUrls":""}} */ urls?: { /** Value */ value?: { /** Multiple URLs can be added separated by comma. Leave empty to block all URLs. * @default PLACEHOLDER */ allowedUrls?: string | Expression<string> | PlaceholderValue; /** Allowed Schemes * @default ["https"] */ allowedSchemes?: Array<'https' | 'http' | 'ftp' | 'data' | 'javascript' | 'vbscript' | 'mailto'>; /** Whether to block URLs with userinfo (user:pass@domain) to prevent credential injection * @displayOptions.show { /operation: ["classify"] } * @default true */ blockUserinfo?: boolean | Expression<boolean>; /** Whether to sanitize URLs with userinfo (user:pass@domain) to prevent credential injection * @displayOptions.show { /operation: ["sanitize"] } * @default true */ blockUserinfo?: boolean | Expression<boolean>; /** Whether to allow subdomains (e.g. sub.domain.com if domain.com is allowed) * @default true */ allowSubdomains?: boolean | Expression<boolean>; }; }; /** Custom * @displayOptions.show { /operation: ["classify"] } * @default {"guardrail":[{"name":"Custom Guardrail"}]} */ custom?: { /** Guardrail */ guardrail?: Array<{ /** Name of the custom guardrail */ name?: string | Expression<string> | PlaceholderValue; /** Minimum confidence threshold to trigger the guardrail (0.0 to 1.0) * @hint Inputs scoring less than this will be treated as violations */ threshold?: number | Expression<number>; /** The system prompt used by the guardrail. Thresholds and JSON output are enforced by the node automatically. */ prompt?: string | Expression<string> | PlaceholderValue; }>; }; /** Custom Regex * @default {} */ customRegex?: { /** Regex */ regex?: Array<{ /** Name of the custom regex. Will be used for replacement when sanitizing. */ name?: string | Expression<string> | PlaceholderValue; /** Regex to match the input text */ value?: string | Expression<string> | PlaceholderValue; }>; }; }; /** * Whether to customize the system message used by the guardrail to specify the output format * @displayOptions.show { /operation: ["classify"] } * @default false */ customizeSystemMessage?: boolean | Expression<boolean>; /** * The system message used by the guardrail to enforce thresholds and JSON output according to schema * @hint This message is appended after prompts defined by guardrails * @displayOptions.show { /customizeSystemMessage: [true] } */ systemMessage?: string | Expression<string> | PlaceholderValue; } export interface LcGuardrailsV2SubnodeConfig { /** * @displayOptions.show { /guardrails.(jailbreak|nsfw|topicalAlignment|custom): [{"_cnd":{"exists":true}}] } */ model: LanguageModelInstance | LanguageModelInstance[]; } interface LcGuardrailsV2NodeBase { type: '@n8n/n8n-nodes-langchain.guardrails'; version: 2; } export type LcGuardrailsV2ParamsNode = LcGuardrailsV2NodeBase & { config: NodeConfig<LcGuardrailsV2Params> & { subnodes: LcGuardrailsV2SubnodeConfig }; }; export type LcGuardrailsV2Node = LcGuardrailsV2ParamsNode;