Description
Is your feature request related to a problem? Please describe.
I don't want the schema of my BaseModel objects to be printed to the screen when my LLM is invoked. I am using Gemini LLM products with this code:
instructor_client = instructor.from_gemini(
client=native_gemini_model,
mode=instructor.Mode.GEMINI_TOOLS,
)
structured_output_instance = instructor_client.create(
response_model=response_model_cls,
messages=messages_for_instructor,
max_retries=max_retries,
)
And each time the schema of response_model_cls
is printed due to line response_model.gemini_schema
in handle_gemini_tools
in instructor.process_response
.
Describe the solution you'd like
If possible, I could add a verbose
arg when creating the instructor client. Something like:
instructor_client = instructor.from_gemini(
client=native_gemini_model,
mode=instructor.Mode.GEMINI_TOOLS,
verbose=False, <-- added!
)
This would prevent the schema from printing to the screen.
Describe alternatives you've considered
I am currently decorating my invocation wrapper with a suppression function:
def suppress_output(func):
"""Decorator to suppress stdout and stderr during function execution."""
@wraps(func)
def wrapper(*args, **kwargs):
with open(os.devnull, "w") as devnull:
with redirect_stdout(devnull), redirect_stderr(devnull):
return func(*args, **kwargs)
return wrapper
Additional context
An example of the printed out schema for this structure:
Structure
class TldrStructuredOutputWithValidation(BaseModel):
"""
Represents the structured TL;DR summary and its references,
with word count validation for each individual bullet point.
"""
word_limit: ClassVar[int] = NUM_WORDS_PER_TLDR
summary_bullet_points: List[str] = Field(
...,
description=f"A list of concise bullet points summarising the most essential conclusions, key findings, and strategic implications from the provided articles. Each bullet point MUST include citations in square brackets (e.g., [1], [2, 3]) corresponding to the source articles. Each individual bullet point must strictly be under {word_limit} words.",
)
references_section_text: List[str] = Field(
...,
description="A list of references. This section lists each source article that was referenced in the summary_bullet_points or provided in the input. Each entry should be formatted as: `[N] <Article URL>`.",
)
@field_validator("summary_bullet_points")
@classmethod
def validate_summary_word_count(cls, v: List[str]) -> List[str]:
"""Validate that each bullet point is under the word limit."""
for i, bullet_point in enumerate(v):
word_count = len(bullet_point.split())
if word_count >= cls.word_limit:
raise ValueError(
f"Bullet point {i+1} has {word_count} words, "
f"which is not strictly under the {cls.word_limit} word limit. "
f"Please shorten this bullet point while retaining key insights."
)
return v
Schema
{'properties': {'summary_bullet_points': {'description': 'A list of concise bullet points summarising the most essential conclusions, key findings, and strategic implications from the provided articles. Each bullet point MUST include citations in square brackets (e.g., [1], [2, 3]) corresponding to the source articles. Each individual bullet point must strictly be under 200 words.', 'items': {'type': 'string'}, 'title': 'Summary Bullet Points', 'type': 'array'}, 'references_section_text': {'description': 'A list of references. This section lists each source article that was referenced in the summary_bullet_points or provided in the input. Each entry should be formatted as: `[N] <Article URL>`.', 'items': {'type': 'string'}, 'title': 'References Section Text', 'type': 'array'}}, 'required': ['references_section_text', 'summary_bullet_points'], 'type': 'object'}
NOTE
I can help to the contribution.