A generated answer is not necessarily ready to use. Post-processing means inspecting and refining it after generation so that its format, content, and wording fit the task. A list for searching customer reviews, for example, needs to be usable as a list—not merely look convincing on screen. section 5.5.3 section 8.4.3
Check the output before passing it along:
- Remove irrelevant comments or excessive explanation, and adjust the language for the intended audience without changing the message. section 8.4.3
- Inspect structure and completeness. A prompt requesting 20 keywords may still return an inconsistently formatted or truncated list; max_tokens limits response tokens, not the number of keywords. section 5.5.3
- Where bias matters, evaluate outputs before adjusting them. Fairness-based reranking, resampling, or reweighing can operate outside the model, but must not replace checking whether the model suits the use case. section 8.5.2
From response to keyword list
An API prompt asks for 20 positive-sentiment keywords for Portuguese customer reviews. Python splits the returned text at newlines. Inspect the resulting entries and count them: the response format can vary, and a low token limit can cut the list short. Revise the prompt if a more consistent format is needed. section 5.5.3
Listing 5.5 Generating keywords via ChatGPT API
from openai import OpenAI
def generate_keywords(temperature=0.5, max_tokens=150):
client = OpenAI(
api_key="your_api_key", # Make sure to use your actual API key here
)
prompt = """Generate a list of 20 keywords indicating positive
sentiment to be used for searching customer reviews in Portuguese."""
try:
response = client.chat.completions.create(
messages=[
{
"role": "user",
"content": prompt,
}
],
model="gpt-4-0125-preview", # Replace with the model you have
access to
temperature=temperature,
max_tokens=max_tokens,
)
return(response.choices[0].message.content.split("\n"))
except Exception as e:
print(f"An error occurred: {str(e)}")
# Example usage
print("Generated Keywords:")
print(generate_keywords())
The API listing shows the newline split that turns generated text into a Python list—and why checking that list matters. section 5.5.3
For consequential outputs, cleanup is not a substitute for validation. Loan-underwriting advice, for instance, calls for examining possible disparities associated with historical training data before relying on an adjusted result. section 8.5.2



