MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / _sanitize_description

Function _sanitize_description

scripts/update_openapi.py:54–90  ·  view source on GitHub ↗

Remove internal, code-centric, or redundant sections from endpoint descriptions. - Strip fenced code blocks - Remove Args/Returns/Raises/Example/Examples/Notes sections - Remove inline curl examples - Avoid provider-implementation specifics like LiteLLM/Bedrock

(text: str)

Source from the content-addressed store, hash-verified

52
53
54def _sanitize_description(text: str) -> str:
55 """Remove internal, code-centric, or redundant sections from endpoint descriptions.
56
57 - Strip fenced code blocks
58 - Remove Args/Returns/Raises/Example/Examples/Notes sections
59 - Remove inline curl examples
60 - Avoid provider-implementation specifics like LiteLLM/Bedrock
61 """
62 import re
63
64 if not text:
65 return text
66
67 # Remove fenced code blocks
68 text = re.sub(r'```[\s\S]*?```', '', text, flags=re.MULTILINE)
69
70 # Remove common docstring sections (until next blank line or end)
71 for header in [
72 r'Args?:',
73 r'Returns?:',
74 r'Raises?:',
75 r'Example[s]?:',
76 r'Notes?:',
77 ]:
78 text = re.sub(rf'(?ms)^\s*{header}.*?(?:\n\s*\n|\Z)', '', text)
79
80 # Remove lines that contain curl examples
81 text = re.sub(r'(?im)^.*\bcurl\b.*$', '', text)
82
83 # Generalize provider-implementation specifics
84 text = re.sub(r'\bLiteLLM\b', 'configured model providers', text)
85 text = re.sub(r'\blitellm\b', 'configured providers', text)
86 text = re.sub(r'\bBedrock\b', '', text)
87
88 # Collapse excessive blank lines and trim
89 text = re.sub(r'\n{3,}', '\n\n', text).strip()
90 return text
91
92
93def _sanitize_spec(spec: dict) -> dict:

Callers 1

_sanitize_specFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected