Validating the presence and validity of links in generated content is essential for ensuring that the content meets specific requirements and maintains a high standard of quality. The following evaluations help ensure that text adheres to link validation criteria:


Definition: Evaluates whether the output text contains at least one valid hyperlink. It checks if the text includes a URL that adheres to standard URL formatting and is accessible.


Evaluation using Interface

input:

  • text: The content column to check.
  • output:
    • result: Passed or Failed

Evaluation using Python SDK

Click here to learn how to setup evaluation using the Python SDK.

Input TypeParameterTypeDescription
Required InputstextstringThe content to be assessed for valid hyperlinks.
OutputTypeDescription
ScoreboolReturns 1.0 if the text contains at least one valid hyperlink, 0.0 otherwise.
from fi.testcases import TestCase
from fi.evals.templates import ContainsValidLink

test_case_valid = TestCase(
    text="Check out our documentation at <https://www.example.com>"
)

template_valid = ContainsValidLink()
response_valid = evaluator.evaluate(eval_templates=[template_valid], inputs=[test_case_valid])

print(f"Score: {response_valid.eval_results[0].metrics[0].value}")
print(f"Reason: {response_valid.eval_results[0].reason}")

What to Do When Contains Valid Link Evaluation Fails:

If the evaluation fails, review the output text to identify the absence of valid links. Consider revising the content to include appropriate hyperlinks that meet the required standards. Providing clearer instructions or constraints in the input can help prevent this issue in future evaluations.


Definition: Evaluates whether the output text does not contain any valid hyperlinks. It checks if the text is free from URLs that adhere to standard URL formatting.

Evaluation using Interface

input:

  • text: The content column to check.
  • output:
    • result: Passed or Failed

Evaluation using Python SDK

Click here to learn how to setup evaluation using the Python SDK.

Input TypeParameterTypeDescription
Required InputstextstringThe content to be assessed for valid links.
OutputTypeDescription
ScoreboolReturns 1.0 if the text does not contain any valid hyperlinks, 0.0 if it contains one or more valid links.
from fi.testcases import TestCase
from fi.evals.templates import NoValidLinks

test_case_no_links = TestCase(
    text="This is a text without any links"
)

template_no_links = NoValidLinks()
response_no_links = evaluator.evaluate(eval_templates=[template_no_links], inputs=[test_case_no_links])

print(f"Score: {response_no_links.eval_results[0].metrics[0].value}")
print(f"Reason: {response_no_links.eval_results[0].reason}")


What to Do When No Valid Links Evaluation Fails:

If the evaluation fails, review the output text to identify the presence of valid links. If the text contains URLs that meet the criteria for valid links, consider revising it to ensure compliance with the requirement of having no valid links. Providing clearer constraints in the input can help ensure adherence in future evaluations.