This prompt is a diagnostic and corrective tool for security engineers and SRE teams who need to resolve TLS certificate validation failures in production or staging environments. It is designed to be embedded inside an automated remediation harness or a security operations copilot. The primary job-to-be-done is to ingest raw certificate data, chain information, and the specific OpenSSL or client error output, then produce a structured diagnosis and a corrected certificate configuration block. Use this prompt when a connection fails with errors such as 'certificate verify failed', 'hostname mismatch', 'self-signed certificate in chain', or 'certificate has expired'. The prompt assumes you already have access to the failing endpoint, the certificate bundle, and the exact error message from the client or OpenSSL command.
Prompt
TLS Certificate Validation Failure Recovery Prompt

When to Use This Prompt
Defines the job-to-be-done, ideal user, required inputs, and operational boundaries for the TLS Certificate Validation Failure Recovery Prompt.
The ideal user is an engineer who understands TLS fundamentals but needs to accelerate root-cause analysis and correction under incident pressure. You must provide the prompt with the raw certificate text (PEM-encoded), the full certificate chain as presented by the server, and the verbatim error output from openssl s_client -connect, curl -v, or your application logs. The prompt is not a substitute for a PKI design workshop. Do not use this prompt for initial certificate generation, designing a certificate authority hierarchy from scratch, or performing cryptographic algorithm selection for a new system. It is a recovery and correction tool, not a greenfield design assistant.
Before invoking this prompt, confirm that you have captured the complete certificate chain and the exact error message. A partial error log or a truncated certificate will lead to an incomplete or incorrect diagnosis. The prompt is most effective when the failure is reproducible and the error message is unambiguous. If the failure is intermittent—caused by network flakiness, load balancer timeouts, or client-side clock skew—this prompt may misattribute the root cause to a certificate misconfiguration. In those cases, rule out transient infrastructure issues before using the prompt.
The output of this prompt is a structured JSON object containing a diagnosis summary, the specific validation failure type, and a corrected certificate configuration block. The corrected configuration may include a revised certificate bundle, updated SAN entries, or a reordered chain. Because the output may be applied directly to production endpoints, you must validate the corrected configuration in a staging environment before deployment. The prompt does not replace your change management process; it accelerates the analysis and drafting phase. Always review the suggested configuration for alignment with your organization's certificate policies, key protection requirements, and compliance obligations.
Use Case Fit
Where this prompt works, where it fails, and the operational preconditions required before wiring it into a production recovery pipeline.
Good Fit: Structured OpenSSL Errors
Use when: The failure is a well-formed OpenSSL verification error (e.g., X509_V_ERR_CERT_HAS_EXPIRED, SSL_ERROR_SYSCALL). The prompt excels at parsing structured error codes and mapping them to specific certificate fields. Avoid when: The error is a generic timeout or network refusal with no TLS diagnostic payload.
Bad Fit: Black-Box Client Errors
Avoid when: The only input is a vague HTTP 500 or a browser ERR_CERT_INVALID without the underlying OpenSSL diagnostic text. The prompt requires the raw certificate bundle and chain to perform SAN matching and expiry analysis. Guardrail: Pre-process client errors to extract the server certificate and full chain before invoking the prompt.
Required Inputs: Certificate Bundle and Chain
Risk: Without the full certificate chain (leaf, intermediates, root), the prompt cannot diagnose chain completeness or trust-anchor issues. Guardrail: The harness must collect the output of openssl s_client -connect [HOST]:[PORT] -showcerts and pipe both the chain and the specific error code into the prompt's [CERTIFICATE_BUNDLE] and [OPENSSL_ERROR] placeholders.
Operational Risk: Automated Remediation
Risk: Directly applying the prompt's suggested certificate configuration to production load balancers or ingress controllers can cause an outage if the root cause is a misconfigured intermediate CA or a revoked certificate. Guardrail: The output must be treated as a diagnostic suggestion. Require human approval in the harness before any kubectl apply or terraform apply of the corrected certificate.
Operational Risk: Expired vs. Misissued Certificates
Risk: The prompt can correctly identify an expired certificate but may suggest a renewal command that fails if the CA is unavailable or the ACME challenge is broken. Guardrail: The harness should validate the prompt's output against the live certificate's notAfter field and check the renewal endpoint's health before suggesting a renewal command.
Variant: Hostname Mismatch Deep-Dive
Use when: The error is specifically SSL_ERROR_BAD_CERT_DOMAIN or a hostname mismatch. The prompt can be adapted to focus exclusively on SAN field comparison. Guardrail: Provide the [EXPECTED_HOSTNAME] as a separate input variable so the prompt can perform an exact string match against the certificate's SAN and CN fields, rather than relying on the generic error message.
Copy-Ready Prompt Template
A reusable prompt template with square-bracket placeholders for diagnosing and recovering from TLS certificate validation failures using OpenSSL error output and certificate bundle context.
This prompt template is designed to be pasted directly into your AI harness for TLS certificate validation failure recovery. It instructs the model to act as a senior security engineer, analyze the provided certificate chain and OpenSSL error output, and produce a corrected certificate configuration. The template uses square-bracket placeholders for all dynamic inputs, allowing you to inject the specific error context, certificate bundle, and operational constraints for each incident.
textYou are a senior TLS security engineer. Your task is to diagnose a TLS certificate validation failure and produce a corrected certificate configuration. ## INPUT - OpenSSL Error Output: [OPENSSL_ERROR_OUTPUT] - Certificate Bundle (PEM format): [CERTIFICATE_BUNDLE] - Target Hostname: [TARGET_HOSTNAME] - Port: [PORT] ## CONSTRAINTS - [CONSTRAINTS] ## OUTPUT SCHEMA Return a JSON object with the following structure: { "diagnosis": { "failure_type": "string (e.g., 'hostname_mismatch', 'expired_certificate', 'incomplete_chain', 'untrusted_root', 'revoked_certificate', 'weak_cipher', 'protocol_mismatch')", "summary": "string (concise explanation of the failure)", "affected_certificate": "string (subject CN or SAN of the problematic cert)" }, "remediation": { "action": "string (e.g., 'replace_certificate', 'add_intermediate', 'update_trust_store', 'correct_san', 'renew_certificate')", "corrected_certificate_pem": "string (the corrected certificate or chain in PEM format, if applicable)", "configuration_changes": [ { "file_path": "string", "key": "string", "old_value": "string", "new_value": "string" } ], "verification_command": "string (the OpenSSL command to verify the fix)" }, "risk_assessment": { "severity": "string (low, medium, high, critical)", "requires_human_review": boolean, "downtime_required": boolean } } ## INSTRUCTIONS 1. Parse the OpenSSL error output to identify the exact failure mode. 2. Inspect the certificate bundle for chain completeness, expiry dates, SAN entries, and signature algorithms. 3. Cross-reference the SAN entries and CN against the target hostname. 4. If the failure is a hostname mismatch, suggest the correct certificate or SAN update. 5. If the chain is incomplete, identify the missing intermediate and construct the full chain. 6. If the certificate is expired, note the expiry date and recommend renewal. 7. If the root is untrusted, identify which trust store needs updating. 8. Always include a verification command that can be run to confirm the fix. 9. Flag any remediation that requires human review, especially for production certificate replacement or trust store modification. 10. Do not generate private keys. Only work with public certificates and chains.
To adapt this template for your environment, replace the square-bracket placeholders with actual values from your incident context. The [OPENSSL_ERROR_OUTPUT] should contain the raw stderr from your openssl s_client -connect or validation command. The [CERTIFICATE_BUNDLE] should include the full PEM-encoded certificate chain being validated. Use [CONSTRAINTS] to specify operational boundaries such as 'no production changes without change approval' or 'prefer updating the trust store over replacing certificates.' After receiving the model output, always validate the corrected_certificate_pem field by running the provided verification_command in a sandboxed environment before applying any changes. For high-severity or production remediation actions, route the output through a human approval step as indicated by the requires_human_review flag.
Prompt Variables
Required inputs for the TLS Certificate Validation Failure Recovery Prompt. Each placeholder must be populated with concrete data extracted from the failed operation before invoking the retry prompt. Missing or malformed inputs will cause the recovery prompt to hallucinate fixes or miss the root cause.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[CERTIFICATE_BUNDLE] | The full certificate chain presented by the server, including leaf, intermediate, and root certificates in PEM format | -----BEGIN CERTIFICATE----- MIID... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- MIID... -----END CERTIFICATE----- | Parse check: must contain at least one valid PEM block. Validate with openssl x509 -text -noout on each block. Null not allowed. |
[OPENSSL_ERROR_OUTPUT] | The complete stderr output from the failed openssl s_client or verify command, including error codes and depth information | verify error:num=20:unable to get local issuer certificate verify return:1 depth=0 CN = *.example.com verify error:num=21:unable to verify the first certificate | Must include the numeric error code and depth chain. Parse for verify error:num= pattern. Null not allowed. |
[TARGET_HOSTNAME] | The hostname or IP address the client attempted to connect to during the failed TLS handshake | api.example.com | Must match the hostname used in the original connection attempt. Validate against SAN entries in the leaf certificate. Null not allowed. |
[TARGET_PORT] | The port number used for the TLS connection attempt | 443 | Must be an integer between 1 and 65535. Validate against the port used in the original openssl s_client -connect argument. Null not allowed. |
[CA_BUNDLE_PATH] | Filesystem path to the trusted CA certificate bundle used during the failed verification, or null if using system default | /etc/ssl/certs/ca-certificates.crt | Path existence check required if non-null. Validate file is readable and contains at least one PEM certificate. Null allowed when system trust store is used. |
[EXPECTED_SAN_ENTRIES] | List of Subject Alternative Name entries the certificate should contain, derived from service discovery or configuration | ["api.example.com", "*.internal.example.com"] | Must be a valid JSON array of strings. Each entry must be a valid DNS name or IP address. Compare against leaf certificate SAN extension. Null allowed when SAN validation is not required. |
[CONNECTION_TIMESTAMP] | ISO 8601 timestamp of when the TLS failure occurred, used to check certificate expiry against the failure moment | 2025-03-15T14:30:00Z | Must parse as valid ISO 8601 datetime. Used to evaluate notBefore and notAfter certificate fields relative to failure time. Null not allowed. |
Implementation Harness Notes
How to wire the TLS certificate validation failure recovery prompt into an automated remediation pipeline or operator tool.
This prompt is designed to be called after a TLS handshake failure is detected by your monitoring or deployment system. The harness should capture the full OpenSSL error output (e.g., openssl s_client -connect host:port), the certificate chain as returned by the server, and the intended hostname. Do not pass raw certificate files directly; instead, extract the text output of openssl x509 -text for each certificate in the chain. The prompt expects these three inputs—[ERROR_OUTPUT], [CERTIFICATE_CHAIN_TEXT], and [TARGET_HOSTNAME]—to be assembled into a single structured context block before invocation.
Wire the prompt into a retry loop with a hard limit of three attempts. After each response, parse the suggested certificate configuration from the model's output. Validate the proposed certificate against the original error using a scripted check: re-run openssl verify -CAfile <suggested_chain> and confirm that the SAN field matches [TARGET_HOSTNAME]. If validation passes, apply the configuration and re-test the TLS handshake. If validation fails or the handshake still errors, feed the new error output back into the prompt as [ERROR_OUTPUT] for the next retry attempt. Log every attempt, the model's raw output, and the validation result for auditability.
For model choice, prefer a model with strong instruction-following and structured output capabilities, such as gpt-4o or claude-3.5-sonnet. Set the temperature low (0.1–0.2) to reduce variability in configuration suggestions. The prompt should be called with a tool definition that enforces the output schema, requiring fields for certificate_configuration, root_cause, and verification_steps. If the model cannot produce a valid configuration after three retries, escalate to a human operator via your incident management system, attaching the full log of attempts and the original error context. Never automatically apply a certificate configuration that fails openssl verify or SAN matching.
Avoid running this prompt in environments where the certificate chain contains sensitive private key material. The harness should strip any private key data from [CERTIFICATE_CHAIN_TEXT] before sending it to the model. If the recovery requires generating a new private key or CSR, the prompt can suggest the command, but the harness must execute key generation locally and never transmit private keys to the model API.
Expected Output Contract
Schema contract for the TLS Certificate Validation Failure Recovery Prompt. The model must return a JSON object with these fields. Validate the output against this contract before applying any suggested configuration changes.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
recovery_summary | string | Non-empty string. Must concisely state the root cause identified from [OPENSSL_ERROR_OUTPUT] and [CERTIFICATE_BUNDLE]. | |
failure_category | string (enum) | Must be one of: 'hostname_mismatch', 'expired_certificate', 'incomplete_chain', 'untrusted_root', 'revoked_certificate', 'protocol_mismatch', 'unknown'. Validate against allowed enum values. | |
suggested_fix | object | Must contain a 'description' (string) and 'configuration_snippet' (string). Snippet must be valid PEM or config block. Null not allowed. | |
san_validation | object | Must contain 'expected_hostname' (string, from [TARGET_HOSTNAME]), 'certificate_sans' (array of strings, extracted from [CERTIFICATE_BUNDLE]), and 'match_found' (boolean). Validate that 'match_found' is true only if 'expected_hostname' is in 'certificate_sans'. | |
chain_analysis | array | Ordered array of objects, each with 'subject' (string), 'issuer' (string), 'expiry' (ISO 8601 date string), and 'status' (enum: 'valid', 'expired', 'untrusted'). Array must not be empty. Validate that the chain order matches the bundle. | |
expiry_status | object | Must contain 'earliest_expiry' (ISO 8601 date string) and 'is_expired' (boolean). Validate that 'is_expired' is true if 'earliest_expiry' is before the current system time. | |
requires_human_review | boolean | Must be true if 'failure_category' is 'untrusted_root' or 'revoked_certificate', or if 'chain_analysis' contains any 'untrusted' status. Otherwise false. | |
confidence_score | number (0.0-1.0) | Float between 0.0 and 1.0. If below 0.7, the harness must escalate for human review regardless of 'requires_human_review' value. Validate range. |
Common Failure Modes
What breaks first when using a TLS Certificate Validation Failure Recovery Prompt and how to guard against it in production.
Hallucinated Certificate Chains
What to watch: The model invents intermediate or root CA certificates that do not exist, creating a syntactically valid but untrustworthy chain. This happens when the prompt does not strictly constrain the model to use only provided certificate data. Guardrail: Explicitly instruct the model to output only certificates present in the provided bundle and validate the output against a known trust store before applying.
Ignoring SAN Mismatch
What to watch: The model focuses on the Common Name (CN) and proposes a fix that ignores a Subject Alternative Name (SAN) mismatch, which is the actual cause of modern browser and client failures. Guardrail: Include a dedicated validation step in the harness that extracts SANs from the proposed certificate and checks them against the target hostname before accepting the model's output.
Overlooking Expired Certificates
What to watch: The model correctly diagnoses a chain issue but fails to notice that a certificate in the chain has already expired, leading to a proposed fix that still results in a validation failure. Guardrail: Add a pre-processing step that parses notBefore and notAfter dates from all certificates and includes a clear EXPIRED flag in the prompt context to force the model's attention.
Incorrect Private Key Matching
What to watch: The model suggests a certificate configuration without verifying that the provided private key corresponds to the leaf certificate's public key, causing a key mismatch error on reload. Guardrail: The application harness must independently verify the modulus match between the proposed certificate and the private key file before deploying the change, and not rely on the prompt for this check.
Brittle OpenSSL Error Parsing
What to watch: The model misinterprets a complex or multi-line OpenSSL error stack, focusing on a secondary error and missing the root cause deep in the stack trace. Guardrail: Pre-process the error output to extract and prioritize the deepest error code in the stack, presenting it as the primary [ROOT_CAUSE] in the prompt to anchor the model's diagnosis.
Recommending Insecure Cipher Suites
What to watch: In attempting to resolve a handshake failure, the model proposes enabling older, insecure cipher suites or downgrading the TLS protocol version, creating a security vulnerability. Guardrail: Include a strict [SECURITY_POLICY] block in the prompt that explicitly forbids TLS versions below 1.2 and lists only approved cipher suites, with a post-generation scan to reject non-compliant suggestions.
Evaluation Rubric
Criteria for evaluating the quality and safety of a TLS certificate validation failure recovery prompt before deploying it in a production security workflow. Each criterion includes a pass standard, a failure signal, and a test method.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Correctness of Suggested Fix | The output suggests a specific, actionable configuration change that directly addresses the root cause of the OpenSSL error. | The suggestion is generic, does not match the error, or introduces a new misconfiguration. | Run 10 known failure cases (e.g., expired cert, hostname mismatch, incomplete chain) and verify the fix resolves the error in a sandbox environment. |
Schema Adherence | The output is valid JSON matching the defined [OUTPUT_SCHEMA] with all required fields present. | The output is not valid JSON, or it is missing required fields like | Parse the output with a JSON validator and check for the presence of all required keys defined in the schema. |
Source Grounding | The | The diagnosis is a hallucination, references information not in the input, or makes a claim without pointing to a specific error line or certificate field. | Automated check: Verify that key strings from the diagnosis (e.g., 'CN=mismatch.example.com') are substrings of the provided input context. |
Safety and Least Privilege | The | The output suggests | Keyword scan for dangerous patterns ( |
Handling of Ambiguity | When multiple causes are possible, the output lists them with confidence levels and suggests a verification step for each. | The output is overconfident in a single diagnosis when the error is ambiguous, or it fails to provide any actionable next step. | Test with an ambiguous error like 'unknown ca' and check if the output provides a ranked list of possibilities (e.g., missing intermediate vs. self-signed). |
Escalation Signal | The | The prompt suggests a workaround for a revoked certificate or a critical policy failure instead of setting | Test with a CRL/OCSP revocation error and assert that |
Idempotency of Output | Running the same input through the prompt multiple times produces a semantically identical diagnosis and fix. | The diagnosis or suggested fix changes significantly between runs without a change in input. | Run the same test case 5 times. Compare the |
Refusal for Non-TLS Inputs | The prompt refuses to process inputs that are not related to TLS certificate validation errors. | The prompt hallucinates a TLS fix for a database connection timeout or an HTTP 500 error. | Provide an input like 'Connection timed out' and assert that the output is a valid refusal message matching the [REFUSAL_POLICY]. |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Use the base prompt with a single certificate file and OpenSSL error output. Skip strict schema validation and focus on getting a corrected PEM block. Accept plain text output.
code[ORIGINAL_CERTIFICATE]: [PASTE PEM HERE] [OPENSSL_ERROR]: [PASTE ERROR TEXT]
Watch for
- Missing SAN field checks in the suggested fix
- Overly broad instructions that suggest disabling verification
- No expiry date validation in the output

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us