import {z} from 'zod' export type ContentFilterAction = 'BLOCK' | 'MASK'; export type BlockedWord = {action: ContentFilterAction, description?: (string | null) | undefined, keyword: string}; export type ContentFilterCategoryConfig = {action: 'BLOCK' | 'MASK', category: string, category_file?: (string | null) | undefined, enabled?: boolean | undefined, severity_threshold?: ('high' | 'medium' | 'low') | undefined} | {[key: string]: unknown}; export type LakeraCategoryThresholds = {jailbreak?: number | undefined, prompt_injection?: number | undefined} | {[key: string]: unknown}; export type BedrockChecksContentFilterCategoryItem = {category: 'VIOLENCE' | 'HATE' | 'SEXUAL' | 'MISCONDUCT' | 'INSULTS'}; export type BedrockChecksContentFilterModel = {categories: Array}; export type BedrockChecksPromptAttackCategoryItem = {category: 'JAILBREAK' | 'PROMPT_INJECTION' | 'PROMPT_LEAKAGE'}; export type BedrockChecksPromptAttackModel = {categories: Array}; export type BedrockChecksSensitiveInformationEntityItem = {type: 'ADDRESS' | 'AGE' | 'AWS_ACCESS_KEY' | 'AWS_SECRET_KEY' | 'CA_HEALTH_NUMBER' | 'CA_SOCIAL_INSURANCE_NUMBER' | 'CREDIT_DEBIT_CARD_CVV' | 'CREDIT_DEBIT_CARD_EXPIRY' | 'CREDIT_DEBIT_CARD_NUMBER' | 'DRIVER_ID' | 'EMAIL' | 'INTERNATIONAL_BANK_ACCOUNT_NUMBER' | 'IP_ADDRESS' | 'LICENSE_PLATE' | 'MAC_ADDRESS' | 'NAME' | 'PASSWORD' | 'PHONE' | 'PIN' | 'SWIFT_CODE' | 'UK_NATIONAL_HEALTH_SERVICE_NUMBER' | 'UK_NATIONAL_INSURANCE_NUMBER' | 'UK_UNIQUE_TAXPAYER_REFERENCE_NUMBER' | 'URL' | 'USERNAME' | 'US_BANK_ACCOUNT_NUMBER' | 'US_BANK_ROUTING_NUMBER' | 'US_INDIVIDUAL_TAX_IDENTIFICATION_NUMBER' | 'US_PASSPORT_NUMBER' | 'US_SOCIAL_SECURITY_NUMBER' | 'VEHICLE_IDENTIFICATION_NUMBER'}; export type BedrockChecksSensitiveInformationModel = {entities: Array}; export type BedrockChecksConfigModel = {contentFilter?: (BedrockChecksContentFilterModel | null) | undefined, promptAttack?: (BedrockChecksPromptAttackModel | null) | undefined, sensitiveInformation?: (BedrockChecksSensitiveInformationModel | null) | undefined}; export type DecisionModelCheck = {action?: ('block' | 'log') | undefined, instructions: string, name: string, threshold?: number | undefined}; export type Mode = {default?: (string | Array | null) | undefined, tags: {[key: string]: string | Array}}; export type CiscoAIDefenseRule = {entity_types?: (Array | null) | undefined, rule_name: 'Code Detection' | 'Harassment' | 'Hate Speech' | 'PCI' | 'PHI' | 'PII' | 'Prompt Injection' | 'Profanity' | 'Sexual Content & Exploitation' | 'Social Division & Polarization' | 'Violence & Public Safety Threats'}; export type CiscoAIDefenseGuardrailConfigModelOptionalParams = {enabled_rules?: (Array | null) | undefined, fallback_on_error?: ('allow' | 'block' | null) | undefined, inspect_path?: (string | null) | undefined, inspection_type?: ('chat' | 'mcp') | undefined, integration_profile_id?: (string | null) | undefined, integration_profile_version?: (string | null) | undefined, integration_tenant_id?: (string | null) | undefined, integration_type?: (string | null) | undefined, on_flagged_action?: (string | null) | undefined, timeout?: (number | null) | undefined} | {[key: string]: unknown}; export type ContentFilterPattern = {action: ContentFilterAction, name?: (string | null) | undefined, pattern?: (string | null) | undefined, pattern_name?: (string | null) | undefined, pattern_type: 'prebuilt' | 'regex'}; export type PiiAction = 'BLOCK' | 'MASK'; export type PiiEntityType = 'CREDIT_CARD' | 'CRYPTO' | 'DATE_TIME' | 'EMAIL_ADDRESS' | 'IBAN_CODE' | 'IP_ADDRESS' | 'NRP' | 'LOCATION' | 'PERSON' | 'PHONE_NUMBER' | 'MEDICAL_LICENSE' | 'URL' | 'MAC_ADDRESS' | 'UUID' | 'US_BANK_NUMBER' | 'US_DRIVER_LICENSE' | 'US_ITIN' | 'US_PASSPORT' | 'US_SSN' | 'US_MBI' | 'US_NPI' | 'UK_NHS' | 'UK_NINO' | 'UK_PASSPORT' | 'UK_POSTCODE' | 'UK_VEHICLE_REGISTRATION' | 'UK_DRIVING_LICENCE' | 'ES_NIF' | 'ES_NIE' | 'ES_PASSPORT' | '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' | 'IN_GSTIN' | 'FI_PERSONAL_IDENTITY_CODE' | 'DE_TAX_ID' | 'DE_TAX_NUMBER' | 'DE_VAT_ID' | 'DE_PASSPORT' | 'DE_ID_CARD' | 'DE_FUEHRERSCHEIN' | 'DE_SOCIAL_SECURITY' | 'DE_HEALTH_INSURANCE' | 'DE_LANR' | 'DE_BSNR' | 'DE_KFZ' | 'DE_HANDELSREGISTER' | 'DE_PLZ' | 'KR_RRN' | 'KR_FRN' | 'KR_PASSPORT' | 'KR_DRIVER_LICENSE' | 'KR_BRN' | 'CA_SIN' | 'SE_PERSONNUMMER' | 'SE_ORGANISATIONSNUMMER' | 'TH_TNIN' | 'TR_NATIONAL_ID' | 'TR_LICENSE_PLATE' | 'NG_NIN' | 'NG_VEHICLE_REGISTRATION' | 'PH_TIN' | 'PH_UMID' | 'PH_PASSPORT' | 'ZA_ID_NUMBER'; export type ToolPermissionRule = {allowed_param_patterns?: ({[key: string]: string} | null) | undefined, decision: 'allow' | 'deny', id: string, tool_name?: (string | null) | undefined, tool_type?: (string | null) | undefined}; export type LitellmParams = {action?: ('block' | 'mask') | undefined, additional_provider_specific_params?: ({[key: string]: unknown} | null) | undefined, advisory_system_message?: (string | null) | undefined, akto_account_id?: (string | null) | undefined, akto_api_key?: (string | null) | undefined, akto_base_url?: (string | null) | undefined, akto_metadata?: ({[key: string]: unknown} | null) | undefined, akto_vxlan_id?: (string | null) | undefined, anonymize_input?: (boolean | null) | undefined, api_base?: (string | null) | undefined, api_endpoint?: (string | null) | undefined, api_id?: (string | null) | undefined, api_key?: (string | null) | undefined, api_version?: (string | null) | undefined, application?: (string | null) | undefined, application_id?: (string | null) | undefined, assertions?: (Array | null) | undefined, asset_id?: (string | null) | undefined, async_mode?: (boolean | null) | undefined, auth_token?: (string | null) | undefined, aws_access_key_id?: (string | null) | undefined, aws_bedrock_runtime_endpoint?: (string | null) | undefined, aws_external_id?: (string | null) | undefined, aws_profile_name?: (string | null) | undefined, aws_region_name?: (string | null) | undefined, aws_role_name?: (string | null) | undefined, aws_secret_access_key?: (string | null) | undefined, aws_session_name?: (string | null) | undefined, aws_session_token?: (string | null) | undefined, aws_sts_endpoint?: (string | null) | undefined, aws_web_identity_token?: (string | null) | undefined, base_url?: (string | null) | undefined, block_failures?: (boolean | null) | undefined, block_on_error?: (boolean | null) | undefined, block_on_violation?: (boolean | null) | undefined, blocked_languages?: (Array | null) | undefined, blocked_words?: (Array | null) | undefined, blocked_words_file?: (string | null) | undefined, breakdown?: (boolean | null) | undefined, categories?: (Array | null) | undefined, category_thresholds?: (LakeraCategoryThresholds | null) | undefined, ccr_retrieval?: boolean | undefined, checks?: (BedrockChecksConfigModel | Array | null) | undefined, chunk_budget_chars?: number | undefined, client_id?: (string | null) | undefined, client_secret?: (string | null) | undefined, confidence_threshold?: number | undefined, config?: ({[key: string]: unknown} | null) | undefined, content_filter_threshold?: (number | null) | undefined, content_moderation_check?: (boolean | null) | undefined, context_source?: ('ENDPOINT' | 'AGENTIC' | null) | undefined, contextual_grounding_from_messages?: boolean | undefined, credentials?: (string | null) | undefined, custom_code?: (string | null) | undefined, decision_model?: (string | null) | undefined, deepkeep_firewall_id?: (string | null) | undefined, default_action?: ('allow' | 'deny') | undefined, default_on?: (boolean | null) | undefined, deployment_name?: (string | null) | undefined, detect_execution_intent?: boolean | undefined, detect_secrets_config?: ({[key: string]: unknown} | null) | undefined, detector_id?: (string | null) | undefined, detectors?: ({[key: string]: unknown} | null) | undefined, dev_info?: (boolean | null) | undefined, disable_exception_on_block?: (boolean | null) | undefined, end_session_after_n_fails?: (number | null) | undefined, evaluation_id?: (string | null) | undefined, experimental_use_latest_role_message_only?: (boolean | null) | undefined, extra_headers?: (Array | null) | undefined, fail_on_error?: (boolean | null) | undefined, file_guardrail_timeout?: (number | null) | undefined, gateway_name?: (string | null) | undefined, grounding_check?: (boolean | null) | undefined, grounding_strictness?: ('BALANCED' | 'STRICT' | null) | undefined, guard_name?: (string | null) | undefined, guardrail: string, guardrailIdentifier?: (string | null) | undefined, guardrailVersion?: (string | null) | undefined, guardrail_timeout?: (number | null) | undefined, hallucinations_check?: (boolean | null) | undefined, include_evidence?: (boolean | null) | undefined, include_scanners?: (boolean | null) | undefined, inspect_embeddings?: (boolean | null) | undefined, is_detector_server?: (boolean | null) | undefined, keyword_redaction_tag?: (string | null) | undefined, lasso_conversation_id?: (string | null) | undefined, lasso_user_id?: (string | null) | undefined, location?: (string | null) | undefined, logging_only_continue_on_input_failure?: (boolean | null) | undefined, logging_only_scope?: ('input' | 'output' | null) | undefined, mask?: (boolean | null) | undefined, mask_request_content?: (boolean | null) | undefined, mask_response_content?: (boolean | null) | undefined, max_concurrent_decision_calls?: (number | null) | undefined, max_input_chars?: (number | null) | undefined, metadata?: ({[key: string]: unknown} | null) | undefined, mock_redacted_text?: ({[key: string]: unknown} | null) | undefined, mode: string | Array | Mode, model?: (string | null) | undefined, monitor_mode?: (boolean | null) | undefined, on_disallowed_action?: ('block' | 'rewrite') | undefined, on_flagged?: ('block' | 'monitor' | 'inject_system_message' | null) | undefined, on_flagged_action?: (string | null) | undefined, on_sensitive_data?: ('block' | 'route' | null) | undefined, on_violation?: ('warn' | 'end_session' | 'block' | 'alert' | null) | undefined, only_scan_new_messages?: (boolean | null) | undefined, optional_params?: (CiscoAIDefenseGuardrailConfigModelOptionalParams | null) | undefined, output_parse_pii?: (boolean | null) | undefined, pangea_input_recipe?: (string | null) | undefined, pangea_output_recipe?: (string | null) | undefined, pattern_redaction_format?: (string | null) | undefined, patterns?: (Array | null) | undefined, payload?: (boolean | null) | undefined, persist_session?: (boolean | null) | undefined, pii_check?: (boolean | null) | undefined, pii_confidence_threshold?: (number | null) | undefined, pii_entities_config?: ({[key: string]: PiiAction} | null) | undefined, policy_id?: (number | null) | undefined, policy_name?: (string | null) | undefined, policy_names?: (Array | null) | undefined, post_checkpoint_id?: (string | null) | undefined, pre_checkpoint_id?: (string | null) | undefined, presidio_ad_hoc_recognizers?: (string | null) | undefined, presidio_analyze_chunk_size_bytes?: (number | null) | undefined, presidio_analyzer_api_base?: (string | null) | undefined, presidio_anonymizer_api_base?: (string | null) | undefined, presidio_entities_deny_list?: (Array | null) | undefined, presidio_filter_scope?: ('input' | 'output' | 'both' | null) | undefined, presidio_language?: (string | null) | undefined, presidio_run_on?: ('input' | 'output' | 'both' | null) | undefined, presidio_score_thresholds?: ({[key: string]: number} | null) | undefined, project_id?: (string | null) | undefined, prompt_attack_threshold?: (number | null) | undefined, prompt_injections?: (boolean | null) | undefined, realtime_violation_message?: (string | null) | undefined, rules?: (Array | null) | undefined, run_in_parallel?: (boolean | null) | undefined, sanitize_error_detail?: (boolean | null) | undefined, scan_only_tool_results?: (boolean | null) | undefined, scan_raw_request?: (boolean | null) | undefined, send_user_api_key_alias?: (boolean | null) | undefined, send_user_api_key_team_id?: (boolean | null) | undefined, send_user_api_key_user_id?: (boolean | null) | undefined, sensitive_data_route_to_model?: (string | null) | undefined, severity_threshold?: (string | null) | undefined, singulr_api_base?: (string | null) | undefined, singulr_api_key?: (string | null) | undefined, singulr_application_id?: (string | null) | undefined, singulr_guardrail_id?: (string | null) | undefined, skip_system_message_in_guardrail?: (boolean | null) | undefined, skip_tool_message_in_guardrail?: (boolean | null) | undefined, skip_unscannable_attachments?: (boolean | null) | undefined, sticky_session_routing?: (boolean | null) | undefined, stream_scope?: ('streaming' | 'non_streaming' | 'both' | {[key: string]: 'streaming' | 'non_streaming' | 'both'} | null) | undefined, template_id?: (string | null) | undefined, tenant_id?: (string | null) | undefined, timeout?: (number | null) | undefined, tool_selection_quality_check?: (boolean | null) | undefined, tracker_api_base?: (string | null) | undefined, tracker_api_key?: (string | null) | undefined, unreachable_fallback?: ('fail_closed' | 'fail_open') | undefined, use_v2?: (boolean | null) | undefined, verify_ssl?: (boolean | null) | undefined, version?: (number | null) | undefined, violation_message_template?: (string | null) | undefined, xecguard_model?: (string | null) | undefined} | {[key: string]: unknown}; export type Guardrail = {created_at?: (string | null) | undefined, guardrail_id?: (string | null) | undefined, guardrail_info?: ({[key: string]: unknown} | null) | undefined, guardrail_name: string, litellm_params: LitellmParams, policy_template?: (string | null) | undefined, updated_at?: (string | null) | undefined}; export type UpdateGuardrailRequest = {guardrail: Guardrail}; export type UpdateApiGuardrailsGuardrailIdArgs = {guardrail_id: string, body: UpdateGuardrailRequest}; export type UpdateApiGuardrailsGuardrailIdOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiGuardrailsGuardrailIdResponse = z.unknown(); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update Guardrail * * PUT /guardrails/{guardrail_id} */ export const updateApiGuardrailsGuardrailId = async (args: UpdateApiGuardrailsGuardrailIdArgs, options: UpdateApiGuardrailsGuardrailIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("x-litellm-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/guardrails/${encodeURIComponent(String(args.guardrail_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiGuardrailsGuardrailIdResponse, await res.json()) };