Validating the presence and correctness of links in generated content is crucial for ensuring quality, accessibility, and compliance with content requirements. Links should be correctly formatted, functional, and aligned with the intended content policies.

Failure to validate links can result in:

  • Broken links – Directing users to non-existent pages.
  • Security risks – Linking to malicious or unverified sources.
  • Non-compliance – Violating content guidelines or accessibility standards.

To maintain content integrity, two key evaluations are used:

These evaluations help enforce link validation policies, improve content quality, and maintain proper hyperlink standards.


Evaluates whether the output text contains at least one valid link. It checks if the text includes a URL that adheres to standard URL formatting.

Click here to read the eval definition of Contains Valid Link

a. Using Interface

Required Inputs

  • text: The content to be assessed for valid hyperlinks.

Output

Returns a Pass/Fail result as 1.0 and 0.0 respectively:

  • Pass – The text contains at least one valid hyperlink.
  • Fail – No valid hyperlinks are found in the text.

b. Using SDK

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}")


Ensures that the output text does not contain any valid hyperlinks. It checks whether the text is free from URLs that match standard URL formatting rules.

Click here to read the eval definition of No Valid Links

a. Using Interface

Required Inputs

  • text: The content to be assessed for valid links.

Output

Returns objective output as 1.0 or 0.0, where 1.0 means the text does not contain any valid hyperlinks and 0.0 means the text contains one or more valid hyperlinks.

b. Using SDK

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}")